Frame Busting 破坏程序不完全适用于 IE

发布于 2024-12-07 07:23:49 字数 2161 浏览 0 评论 0原文

我一直在开发一个 Framebustingbuster(名字是什么,呵呵),它可以让我的用户留在我的页面上,并打开一个带有目标 URL 的新窗口。我正在使用 Lightbox 脚本来显示 iframe,这就是我正在做的事情:

1)为所有 .lightbox 点击添加了一个事件,fe:

$('.lightbox').live("click", function(e) { 
  e.preventDefault(); 
  $('#redirectURL').val($(this).attr('href')); 
  $(this).lightbox(); 
}

2)添加了框架破坏破坏者:

<script type="text/javascript">
    var prevent_bust = 0  
    window.onbeforeunload = function() { prevent_bust++ }  
    setInterval(function() {  
      if (prevent_bust > 0) {  
        prevent_bust -= 2  
        window.top.location = 'http://server-which-responds-with-204.com'  
      }  
    }, 1)  
</script>

3)修改了框架破坏破坏者代码以适应我的需求是:

  • 检测 iframe 是否想要更改 window.top.location
  • 如果是,则使用 204 服务器响应防止这种情况发生
  • 打开一个新页面: window.open( $('#redirectURL', '_blank' );
  • 关闭灯箱: $('.jquery-lightbox-button-close').click();

到目前为止,这就是我想出了:

var prevent_bust = 0  
window.onbeforeunload = function() { prevent_bust++ }  
setInterval(function() {  
  if (prevent_bust > 0) {  
    prevent_bust -= 2;
    redirectURL = $('#redirectURL').val();
    if(redirectURL != "") {
        window.top.location = 'http://www.****.com/ajax/nocontent.php';
        window.open(redirectURL, "_blank");
        $('.jquery-lightbox-button-close').click();
        $('#redirectURL').val('');
    } else {
        window.top.location = 'http://www.****.com/ajax/nocontent.php';
    }
  }  
}, 1); 

// 编辑: 在我忘记之前,“nocontent.php”是一个返回 204 标头的文件

对于 Firefox,如果检测到更改,它会按照我编程的方式运行这window.top.location 它打开一个新的框架/页面并阻止 iframe 重新加载顶部位置并将其四舍五入,它关闭

Safari/Chrome 行为类似,它们打开一个新的浏览器屏幕(不是)确定是否有一个选项可以说 target="_newtab" 或其他内容? 唯一不好的是它们并没有真正显示弹出窗口被阻止的消息,但我可以通过在上面显示弹出气球来解决这个问题。我的网站有一个链接 页。

令人震惊的是,Internet Explorer 是唯一剩下的害群之马。IE 不会打开新的弹出窗口,也不会阻止 iFrame 重置的 window.top.location,而只是继续将整个页面刷新到“#targetURL”。它与默认的破坏代码执行相同的操作..所以这不是因为我的一些编辑。

谁能发现我的代码中的错误?

另外,我需要进行一些修改,看看请求是由 iframe 还是由用户本身发出,因为现在用户实际上没有任何选项可以通过更改工具栏中的地址或单击链接,这并不是真正需要的哈哈。

提前致谢。

I've been working on a Frame busting buster (what's in a name, hehe), which kept my users on my page and open a new window with the target URL. I'm using a Lightbox script to display iframes, this is what I'm doing:

1) Added an event for all .lightbox clicks, f.e:

$('.lightbox').live("click", function(e) { 
  e.preventDefault(); 
  $('#redirectURL').val($(this).attr('href')); 
  $(this).lightbox(); 
}

2) Added a frame busting buster:

<script type="text/javascript">
    var prevent_bust = 0  
    window.onbeforeunload = function() { prevent_bust++ }  
    setInterval(function() {  
      if (prevent_bust > 0) {  
        prevent_bust -= 2  
        window.top.location = 'http://server-which-responds-with-204.com'  
      }  
    }, 1)  
</script>

3) Modified the frame busting buster code to fit my needs, which are:

  • detect if an iframe wants to change the window.top.location
  • if so, prevent this from happening using the 204 server respond
  • open a new page: window.open( $('#redirectURL', '_blank' );
  • close lightbox: $('.jquery-lightbox-button-close').click();

So far, this is what I've come up with:

var prevent_bust = 0  
window.onbeforeunload = function() { prevent_bust++ }  
setInterval(function() {  
  if (prevent_bust > 0) {  
    prevent_bust -= 2;
    redirectURL = $('#redirectURL').val();
    if(redirectURL != "") {
        window.top.location = 'http://www.****.com/ajax/nocontent.php';
        window.open(redirectURL, "_blank");
        $('.jquery-lightbox-button-close').click();
        $('#redirectURL').val('');
    } else {
        window.top.location = 'http://www.****.com/ajax/nocontent.php';
    }
  }  
}, 1); 

// EDIT: Before I forget, 'nocontent.php' is a file that returns a 204 header

For Firefox it acts as I programmed it, if there's a change detected in the window.top.location it opens a new frame/page and prevents the iframe from reloading the top location and to round it up, it closes the jQuery lightbox.

Safari/Chrome act similar, they open a new browser screen (not sure if theres an option to say target="_newtab" or something?). Only bad thing is they do not really display a message of the popup is blocked, but I can work around that by displaying a popup balloon on my website with a link to the page.

Internet Explorer is, what a shocker, the only black sheep left.. IE does not open a new popup, nor blocks the window.top.location reset by the iFrame and simply continues refreshing the complete page to the '#targetURL'. It does the same with the default busting code.. so it's not because of some of my edits.

Anyone who is able to spot a mistake in my code?

Also, I would need a little modification that sees if the request has been made by an iframe or by the user itself, because now there is really NO option for a user to leave my page by changing the address in the toolbar or by clicking a link, which is not really needed LOL.

Thanks in advance.

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

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

发布评论

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

评论(2

水中月 2024-12-14 07:23:49

PENDO,我试图模拟你描述的整个过程,ligthbox-jquery,javascript自己的代码和控件通过lightbox打开页面。我根本无法模拟,随着时间的流逝,我正在发送建议以扩大可能性和解决方案的范围。
我建议替换重定向页面:

 ...
  redirectUrl = $ ('# redirectUrl'). val ();
 ...
 window.top.location = 'http://www .****. with / ajax / nocontent.php';
 window.open (redirectUrl, "_blank");

替换为模拟页面的 DIV 容器,使用 ajax 调用并获取内容并覆盖 DIV 的内容。

 ...
 $.post(redirectoURL /* or desired URL */, function(data) {
     $('DIV.simulateContent').html(data);
 });
 ...

或者

 ...
 $('DIV.simulateContent').load(redirectoURL);
 ...

这种方法还避免了阻止用户使用地址栏离开您的页面的问题(正如您自己提到的)。

抱歉,让我给你一个完整的解决方案,但时间阻止了我。

PENDO,在问题的替代方案上做更多的工作,我发现了一个可定制的 jQuery lightbox 插件,用于处理自定义窗口(iframe、html、内联 ajax 等)。也许会有帮助。以下链接:

 http://jacklmoore.com/colorbox/

PENDO, I tried to simulate the whole process you described, ligthbox-jquery, javascript their own codes and controls opening pages via lightbox. I could not simulate at all, and as time is running out I'm sending a suggestion to broaden the range of possibilities and solutions.
I suggest replacing the redirect page:

 ...
  redirectUrl = $ ('# redirectUrl'). val ();
 ...
 window.top.location = 'http://www .****. with / ajax / nocontent.php';
 window.open (redirectUrl, "_blank");

Replaced with a DIV container that simulates a page, using ajax calls and taking the content and overwritten the contents of the DIV.

 ...
 $.post(redirectoURL /* or desired URL */, function(data) {
     $('DIV.simulateContent').html(data);
 });
 ...

or

 ...
 $('DIV.simulateContent').load(redirectoURL);
 ...

This approach also avoids the problem of preventing the user from even leaving your page using the address bar (as you yourself mentioned).

Sorry, let me give you a complete solution, but time prevented me.

PENDO, a little more work on alternatives to the problem, I found a customizable jQuery lightbox plugin for working with custom windows yet (iframe, html, inline ajax etc.). Maybe it will help. The following link:

 http://jacklmoore.com/colorbox/
幼儿园老大 2024-12-14 07:23:49

如果您不需要在 IE 中的 iframe 中运行 javascript,则可以设置 iframe 安全属性:

<iframe security="restricted" src="http://domain.com" />

http://msdn.microsoft.com/en-us/library/ms534622(v=VS.85).aspx

If you don't need javascript running in your iframe in IE, you can set the iframe security attribute :

<iframe security="restricted" src="http://domain.com" />

http://msdn.microsoft.com/en-us/library/ms534622(v=VS.85).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文