【问题标题】:blocking frames and iframes with javascript使用 javascript 阻止框架和 iframe
【发布时间】:2013-10-30 14:44:23
【问题描述】:

我一直在寻找一种解决方案,以防止从我的网站以外的任何地方加载我的网站。意思是我可以阻止或至少采取措施阻止我的网站加载到其他网站的框架和 iframe 中。对于类似的问题,我在这里看到了一些有用的答案,但我想知道从另一个方向着手。如果 www.mysite.com/ 以外的任何其他内容,是否可以加载检查浏览器 url,然后强制重新加载 www.mysite.com/ 。由于我对其他语言的熟悉程度有限,这可以用 javascript 完成吗? 这是我正在尝试的代码示例,但它没有按我想要的方式工作。它仅重新加载 iframe 并允许保留浸出站点。我需要强制将整页重新加载到我的网站。我错过了什么?

    <script type="text/javascript" language="JavaScript">
    <!-- 
    if( -1 == location.href.
       toLowerCase().
       indexOf('mysite.com') )
    {
      location.href = 'http://mysite.com';
    }
    // -->
    </script> 

【问题讨论】:

标签: javascript frameset-iframe


【解决方案1】:

可从here 获得的 FrameBuster 列表并粘贴在下方以供将来参考。


1.

if (window.top!=window.self){window.top.location="thepage_the_buster_is_on.php";}

2.

if (top.location!= location) {top.location.replace(self.location.href);}

3.

if( window!= window.top ) {top.location.href = location.href;}

4.

if (top.location!= location) {top.location.href = document.location.href;}

5.

if (parent.frames.length &gt; 0) top.location.replace(document.location);

【讨论】:

  • 我认为这行不通。您不能从其他域修改顶部位置。
  • 因此无法从框架/iframe 中加载新页面。我确信我之前已经看到允许 iframe 在单击时加载新页面的代码。如果 url = 我以外的任何内容,我只希望它在加载时发生?
  • Kazzzaaa 谢谢 Asryael。我尝试了您的代码,但不幸的是它使我的网站崩溃了。不知道为什么,但无论如何我只从你那里抢到顶线,这似乎正是我想要的。一直在窃取我的网站现在每次尝试将我放入 iframe 时都会重新加载我的网站。这是我用的。
  • 是的,谢谢你,Asryael 我只使用了你脚本的一部分,但它成功了。非常感谢
  • @DavidJohnson 如果对您有帮助,请在左侧标记为答案。
猜你喜欢
  • 2011-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多