与弹出窗口相关的javascript问题

发布于 2024-11-05 18:42:04 字数 669 浏览 7 评论 0原文

我需要一个用户无法刷新的弹出窗口。为此,我正在尝试这样做:

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 技术交流群。

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

发布评论

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

评论(1

情定在深秋 2024-11-12 18:42:04

newWindow.onload = setUnloadHandler;

从您的示例中尚不清楚,但可能 newWindow 包含来自其他站点的文档。由于同源政策,您无法编写脚本。

另外,浏览器不会让你做任何事情来阻止 onunload 处理程序中的卸载,因为它很令人讨厌并且用户讨厌它 - 还记得以前允许这样做的日子,并被滥用来生成无尽的无法关闭的色情内容弹出循环?

您无法获得不可刷新的窗口。您尝试这样做的目的是什么?

newWindow.onload = setUnloadHandler;

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?

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