admin管理员组文章数量:1287594
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?
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?
Share Improve this question edited Feb 1, 2011 at 14:57 Sachin Shanbhag 55.5k11 gold badges91 silver badges103 bronze badges asked Feb 1, 2011 at 14:53 BlankmanBlankman 267k330 gold badges795 silver badges1.2k bronze badges4 Answers
Reset to default 5Yes 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 ments.
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.
};
It looks like a "frame buster" routine. Whether such things work seems to be a controversial topic.
window.top stands for the topmost window in your browser. In Simple words, its the browser window itself.
The code seems to be clearing all the iframes with blank.
Is this making sure the page isn't rendering inside of a iframe?
An iframe
or a frame
, yeah. It's trying to break out.
本文标签: javascriptwhat is this windowtop check performing is this checking for an iframeStack Overflow
版权声明:本文标题:javascript - what is this window.top check performing? is this checking for an iframe? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741277312a2369803.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论