与弹出窗口相关的javascript问题
我需要一个用户无法刷新的弹出窗口。为此,我正在尝试这样做:
function openNewWindow(href){
alert("hello here");
var newWindow = window.open(href, 'newWindow',
'toolbar=no,location=no,directories=no,status=no, menubar=no,resizable=no,width=1024,height=400');
return false;
}
<a onclick="return openNewWindow(this.href);" href="newPage.html" >Click me</a>
newPage.html
window.onunload = check;
function check(){
alert("hey");
return false;
}
当我尝试重新加载浏览器时,会生成此警报。但 return false;
不起作用。
或者是否可以在新弹出的窗口中没有导航栏
。
所以请帮忙
I need a pop window which could not be refreshed by user. for that i am trying this:
function openNewWindow(href){
alert("hello here");
var newWindow = window.open(href, 'newWindow',
'toolbar=no,location=no,directories=no,status=no, menubar=no,resizable=no,width=1024,height=400');
return false;
}
<a onclick="return openNewWindow(this.href);" href="newPage.html" >Click me</a>
newPage.html
window.onunload = check;
function check(){
alert("hey");
return false;
}
Here alert is generated when i try to reload the browser. but return false;
is not working.
Or if it is possible to not to have Navigation bar
in newly pop up window.
So please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的示例中尚不清楚,但可能
newWindow
包含来自其他站点的文档。由于同源政策,您无法编写脚本。另外,浏览器不会让你做任何事情来阻止 onunload 处理程序中的卸载,因为它很令人讨厌并且用户讨厌它 - 还记得以前允许这样做的日子,并被滥用来生成无尽的无法关闭的色情内容弹出循环?
您无法获得不可刷新的窗口。您尝试这样做的目的是什么?
It's not clear from your example, but probably
newWindow
contains a document from another site. You can't script into it due to the Same Origin Policy.Also, browsers won't let you do anything to prevent an unloading in the
onunload
handler, because it's obnoxious and users hate it—remember the old days when this was allowed, and abused to generate endless uncloseable porn popup loops?You can't get an unrefreshable window. What is your purpose in trying to do so?