如果网站试图逃离框架,如何停止加载网站

发布于 2024-11-18 18:50:55 字数 444 浏览 0 评论 0原文

所以我知道有很多网站试图打破框架(帧破坏),然后存在整个循环的“破坏框架破坏者”和“破坏框架破坏者”等。有没有一种方法可以预测是否网站会尝试突破你的框架吗?我希望我的程序尝试将站点加载到框架中,如果它尝试突破,则放弃尝试并停止加载框架。这是我之前尝试过的:

<iframe id="framed_source" src = "<%= @excerpt.url %>"></iframe>
<script type="text/javascript">
    if ( top === self )
    {
        $(".framed_source").remove();
    }
</script>

不幸的是,即使删除 iframe,它仍然重定向到原始站点?我怎样才能删除框架并完全放弃加载其网站的尝试,这样就不会发生重定向?

So I know that there are many websites out there that try to break from frames (frame-busting) and then there is this whole cyclic "busting frame busters" and "busting frame buster busters" etc. Is there a way to anticipate whether a website will try to break out of your frame? I want my program to try to load the site into a frame, and if it tries to break out, just abandon the attempt and stop loading the frame. This is what I tried before:

<iframe id="framed_source" src = "<%= @excerpt.url %>"></iframe>
<script type="text/javascript">
    if ( top === self )
    {
        $(".framed_source").remove();
    }
</script>

Unfortunately, even with removing the iframe it still redirects to the original site? How can I just remove the frame and abandon the attempt to load their website at all so no redirecting occurs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空宴 2024-11-25 18:50:55

这是一个例子

<div id="pcontent"></div> <!-- Page 1 html -->
<script>
   setInterval(function(){//set interval
       if(!$('iframe').contents().find('#icontent').length)//check if div exists on iframe
          window.location.href= 'blbla.com';//if so redirect
    },100);//end interval
</script>
<iframe> <!-- This is your iframe below is the javascript code should go to page2.html -->
   <div id="icontent"></div>
   <script>
     setInterval(function(){
      if(!top.getElementById('pcontent').length)//check if the div exists on top most window
      window.location.href= 'blbla.com';
     },100);
   </script>
</iframe>

现在: iframe 内部是 iframe 应该有的内容... [仅说明]

您还可以检查其他内容,例如内容是否没有宽度、高度、内部文本和 html 不匹配等...

here is an example

<div id="pcontent"></div> <!-- Page 1 html -->
<script>
   setInterval(function(){//set interval
       if(!$('iframe').contents().find('#icontent').length)//check if div exists on iframe
          window.location.href= 'blbla.com';//if so redirect
    },100);//end interval
</script>
<iframe> <!-- This is your iframe below is the javascript code should go to page2.html -->
   <div id="icontent"></div>
   <script>
     setInterval(function(){
      if(!top.getElementById('pcontent').length)//check if the div exists on top most window
      window.location.href= 'blbla.com';
     },100);
   </script>
</iframe>

Now: Inside the iframe is what the iframe should have ... [illustration only]

You can also check for other things like, if contents don't have width, height, inner text and html don't match etc...

一腔孤↑勇 2024-11-25 18:50:55

使用此代码将提示用户,如果他愿意,他可以保留在您的页面中......(我没有尝试过)

<script type="text/javascript">
    window.onbeforeunload=function(e){
       $(".framed_source").remove();
       return 'Please keep here I will remove that buster iframe!';
    }
<script type="text/javascript">

with this code the user will be prompted, and if he wants he can keep in your page...(I've not tried it)

<script type="text/javascript">
    window.onbeforeunload=function(e){
       $(".framed_source").remove();
       return 'Please keep here I will remove that buster iframe!';
    }
<script type="text/javascript">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文