简体   繁体   English

有什么方法可以防止浏览器在单击“关闭”按钮后关闭

[英]Is there any way to prevent the browser closing after clicking on the “Close” button

My requirement is as follows: 我的要求如下:

When the User clicks the close button on the browser in a page, the customized popup window will appear. 当用户单击页面中浏览器上的close按钮时,将显示customized popup窗口。 I had designed the popup window and I can open that window with the following code: 我已经设计了popup窗口,可以使用以下代码打开该窗口:

 window.onbeforeunload = function (e) {
            openwindow(200, 100, 'Close.aspx');
        };

But my ultimate requirement is that the main parent window should not be closed after clicking any buttons on the popup window. 但我的最终要求是,单击弹出窗口上的any按钮后,不应关闭主父窗口。 I don't want the browser's default alert return message window and I am displaying the popup window here instead of browser's default alert window. 我不希望浏览器的默认警报返回消息窗口,而是在此处显示弹出窗口,而不是浏览器的默认警报窗口。 Is there way to stop the browser closing..? 有没有办法停止浏览器关闭?

Due to security reasons this is not possible! 由于安全原因,这是不可能的!

You can show a confirmation dialog using onbeforeunload (see eg here for how to do it), giving the user the choice to not leave the page after all. 您可以使用onbeforeunload显示确认对话框(请参见此处的操作方法),使用户可以选择不离开页面。 But you can't prevent the closing against the user's will. 但是您不能阻止违反用户意愿的交易。

window.onbeforeunload = function(e) {
    return 'Dialog text here.';
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击任何浏览器的关闭按钮后,javascript中是否有与关闭按钮相关的特定事件? - on clicking the close button of any browser, is there any specific event related to close button, in javascript? 有没有一种方法可以通过单击googlescript或javascript来关闭浏览器? - Is there a way to close the browser using googlescript or javascript, by just clicking a button for it? 如何防止fancybox关闭? 想要使用户单击“关闭”按钮,而不是在浏览器上的任何位置 - How can I prevent fancybox from closing? Want to make the user click the Close button instead of anywhere on the browser Intro.js - 在外面点击时阻止巡回演出的任何方法? - Intro.js - any way to prevent closing of tour when clicking outside? 单击 BROWSER 后退按钮关闭模态 - Close modal by clicking BROWSER back button 有没有其他方法在点击“按钮”后在网站上显示其他文字? - Is there any other way to display other text on website after clicking on “button”? 单击关闭按钮后,模态自动重新打开 - Modal reopens automatically after clicking the closing button 在浏览器上单击任意位置时,防止daterangepicker关闭 - Prevent daterangepicker from closing when clicking anywhere on browser 关于如何防止用户单击保存按钮后(通过onbeforeunload)关闭浏览器窗口的建议? - Recommendations on how to prevent users from closing browser window (via onbeforeunload) AFTER the save button has been clicked? SimpleModal不会在默认按钮单击时关闭(但是在容器侧面单击时将关闭) - SimpleModal not closing on default button click (but will close when clicking on sides of container)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM