简体   繁体   English

Twitter上的javascript以防止嵌入html页面

[英]javascript on twitter to prevent embedding the html page

This is the javascript that you can find in www.twitter.com (just click to see the source code) I have just reformatted it for clarity: 这是你可以在www.twitter.com找到的javascript(只需点击查看源代码)我为了清楚起见重新格式化了它:

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

now I understand this trick is to prevent other sites to wrap twitter in other iframes. 现在我明白这个技巧是为了防止其他网站在其他iframe中包装twitter。 but what I want to ask is do we really need all of this code ? 但我想问的是,我们真的需要所有这些代码吗? what's the need of setting a function to execute in 1 millisecond, one to execute at 'onload' and one now. 设置一个函数在1毫秒内执行的需要是什么,一个在'onload'执行,现在执行一个。

is that paranoia or is it really worth ? 那是偏执还是真的值得?

Many THanks in advance Reg 许多提前谢谢

Most browsers will only open one or two connections to the server while the page is loading, which means the redirect has to sit in the queue while the original copy of the page loads. 大多数浏览器只在页面加载时打开一个或两个与服务器的连接,这意味着重定向必须在页面的原始副本加载时位于队列中。 You may have noticed that the "current" page in the browser remains interactive/useable when you click on a link, until the new page actually starts downloading. 您可能已经注意到,当您单击链接时,浏览器中的“当前”页面仍保持交互/可用,直到新页面实际开始下载。 The timeout/onload stuff kills the content of the page, theoretically aborting any of the in-progress transfers and bumping the redirect to the top of the list. 超时/上传内容会终止页面内容,理论上会中止任何正在进行的传输并将重定向突然显示在列表顶部。 And also prevents the page from being used within the frame/iframe, until the framebuster code has finished. 并且还阻止页面在frame / iframe中使用,直到framebuster代码完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM