Jos*_*ndo 6 javascript iframe jquery framebusting
我一直在制作一个Frame破坏破坏者(名字中有什么,呵呵),它让我的用户保持在我的页面上并打开一个带有目标URL的新窗口.我正在使用Lightbox脚本来显示iframe,这就是我正在做的事情:
1)为所有.lightbox点击添加了一个事件,fe:
$('.lightbox').live("click", function(e) {
e.preventDefault();
$('#redirectURL').val($(this).attr('href'));
$(this).lightbox();
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
3)修改了帧破坏破坏代码以满足我的需求,它们是:
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);
Run Code Online (Sandbox Code Playgroud)
//编辑: Before I forget, 'nocontent.php' is a file that returns a 204 header
对于Firefox,它就像我编写它一样,如果在window.top.location中检测到更改,它会打开一个新的框架/页面并阻止iframe重新加载顶部位置并将其四舍五入,它会关闭jQuery灯箱.
Safari/Chrome的行为类似,他们打开一个新的浏览器屏幕(not sure if theres an option to say target="_newtab" or something?).唯一不好的是他们并没有真正显示弹出窗口被阻止的消息,但我可以通过在我的网站上显示一个带有指向该页面的链接的弹出气球来解决这个问题.
Internet Explorer是一个令人震惊的,唯一的黑羊离开.. IE没有打开一个新的弹出窗口,也没有阻止window.top.location由iFrame重置,只是继续刷新整个页面到'#targetURL'.它与默认的破坏代码一样.所以这不是因为我的一些编辑.
谁能够在我的代码中发现错误?
此外,我需要进行一些修改,看看请求是由iframe还是由用户自己完成,因为现在用户通过更改工具栏中的地址或单击链接,这不是真的需要大声笑.
提前致谢.
PENDO,我试图模拟你描述的整个过程,ligthbox-jquery,javascript自己的代码和控制通过灯箱打开页面.我根本无法模拟,随着时间的推移,我正在提出一个建议,以扩大可能性和解决方案的范围.我建议更换重定向页面:
...
redirectUrl = $ ('# redirectUrl'). val ();
...
window.top.location = 'http://www .****. with / ajax / nocontent.php';
window.open (redirectUrl, "_blank");
Run Code Online (Sandbox Code Playgroud)
替换为模拟页面的DIV容器,使用ajax调用并获取内容并覆盖DIV的内容.
...
$.post(redirectoURL /* or desired URL */, function(data) {
$('DIV.simulateContent').html(data);
});
...
Run Code Online (Sandbox Code Playgroud)
要么
...
$('DIV.simulateContent').load(redirectoURL);
...
Run Code Online (Sandbox Code Playgroud)
这种方法还避免了阻止用户甚至使用地址栏离开页面的问题(正如您自己提到的).
对不起,让我给你一个完整的解决方案,但时间阻止了我.
PENDO,关于问题的替代品的更多工作,我找到了一个可自定义的jQuery灯箱插件,用于处理自定义窗口(iframe,html,内联ajax等).也许它会有所帮助.以下链接:
http://jacklmoore.com/colorbox/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1761 次 |
| 最近记录: |