[英]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.