Hi there, I want to know if a document's top window's URL can be detected through javascript. I mean can an ad network's banner javascript include like <script language="javascript" src="... detect if the page was loaded inside an autosurf frame? I know that you can't read top.location.href unless both top and self are from the same domain. However, google analytics can read it. I'm using an autosurf site now (I know it's a bad idea) to generate infilated hits. I just wonder how can their (google's) script detect that my site was loaded inside another domain's frame? I know it's not a moral thing but I want to learn what can and can't be done. Any help greatly appreciated Best regards,
You could attempt to read top and catch the exception: var inForeignFrameset=false; try { if(top.location.href==location.href) ; }catch(e){inForeignFrameset=true;} Code (markup):
I see. Thanks for your help. But that way you can only find out that the topmost frame is from another domain. You can't get the actual URL. Google analytics somehow logs my autosurf site's domain as a referer. I can't understand how that code can get the URL of the top frame. Any different ideas?
well, thanks a lot for your concern but unfortunately document.referrer simply gets the referer and I'm already cloaking the referer with nested frames etc. I checked again after your reply, but document.referrer returns what I expect it to return - not the autosurf domain. so does google have a special javascript function that somehow reads the "top"s URL? Aren't those guys using the same language and are limited to the same boundaries as we are? Any ideas?
You need to read the referrer of the highest accessible level. You could try something like this (untested): var parentRef=self, referrer=document.referrer; try { while(parentRef=parentRef.parent) referrer=parentRef.document.referrer; }catch(e){} Code (markup):
well, thanks a lot. You're right. Altough you can't get "top"s location, you can get the nested frame's referrer, which in my case corresponds to the same URL. parent.document.referrer this gives the foreign domain. thanks again... best regards