Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is this window.top check performing? is this checking for an iframe?

if(window.top!==window.self){document.write="";
window.top.location=window.self.location;
setTimeout(function(){document.body.innerHTML=""},1);
window.self.onload=function(){document.body.innerHTML=""}};

Is this making sure the page isn't rendering inside of a iframe?

like image 474
Blankman Avatar asked Oct 12 '25 11:10

Blankman


1 Answers

Yes it would seem that this script attempts makes itself the parent frame if it isn't already. AS Pointy has said, these don't always work. Javascript cannot "break out" of it's owner document in most browsers unless it created that document. Or if the page containing the Javascript was loaded dynamically in such a way that the Same Domain policy isn't in effect. (Likely not the case if your site is in an iframe/frame) In the case of a page that is being opened inside another, the script should not have access to modify the parent document.

Here's the code you posted broken out onto several lines with comments.

if(window.top!==window.self){ // is the outermost document not this document?
  document.write=""; // write an empty text node to the document. (not sure why)
  window.top.location=window.self.location; // set the parent document's location to this document's location.
  setTimeout( function(){document.body.innerHTML=""}, 1); // after 1 millisecond make this document's HTML empty. (Probably a memory leak fix)
  window.self.onload = function(){document.body.innerHTML=""} // Another memory leak fix to clear the current document when it is done loading.
};
like image 131
sholsinger Avatar answered Oct 13 '25 23:10

sholsinger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!