比如,我有一个页面a.html<html>
<title>I want to prevent being redirected</title>
<body>
<a href="b.html" target="_blank">open window b</a>
</body>
<html>当点击上面的链接后,打开b.html<html>
<title>I will redirect opener</title>
<script language="JavaScript">
function redirect()
{
window.opener.open("http://www.163.com", '_self');
}
</script>
<body onload="redirect()">
I will redirect opener to www.163.com
</body>
<html>b.html会调用window.opener.open 或 也可通过window.opener.location来把a.html重定向到别的网站。【问题来了】 请问在a.html有没有什么办法进行限制,使得b.html中的window.opener.open无效?
这样不可以吗
或者子窗口 用 window.opener 来导致的重定向!
不过在firefox 中 beforeunload 的 event 值,是判断不了那些情况的!IE的可以!
if(window.addEventListener){
window.addEventListener('beforeunload', function(e){ },false);
}else{
window.attachEvent('onbeforeunload',function(){ });
}
膜拜下真正的系统程序员。
仅供参考,没测试a页面
要是想定向
<a href="b.html?state=1" target="_blank">open window b</a>
不定向
<a href="b.html?state=1" target="_blank">open window b</a>
function redirect()
{
var state=location.href.split('=');
if(state[1]==1)
{
window.opener.open("http://www.163.com", '_self');
}
else
{
return false;
}
}
<a href="b.html" target="_blank">open window b</a>
感谢各位的回复。
不好意思,今天比较忙,没有来得及回复哈~
本人js比较菜哈,但是又想出两道笔试题 ^_^第二个问题来了,在a.html中,不修改window.open('Untitled-1.html').opener=null;的前提下即确保b.html中的window.opener是一个window对象的前提下,能否在a.html中设置,使得b.html中的
window.opener.open方法无效。 但是window.opener.status="xxxx"有效