简体   繁体   English

Javascript如何:隐藏onBeforeUnload的浏览器弹出窗口并显示自定义弹出窗口

[英]Javascript How To : hide the browser popup for onBeforeUnload and display custom popup

I am building a MMO which has a tutorial in it. 我正在构建一个包含教程的MMO。

When the user tries to navigate away from the tutorial or close the tab/browser while on the tutorial, I need to show a custom popup which has a options as to why the person is quitting the tutorial. 当用户尝试离开本教程或在本教程上关闭选项卡/浏览器时,我需要显示一个自定义弹出窗口,其中包含有关此人为什么退出本教程的选项。

I am familiar with the onbeforeunload event but my requirement is to display the custom popup instead of the browser default popup as it can't be customized other than changing the text message. 我熟悉onbeforeunload事件,但我的要求是显示自定义弹出窗口,而不是浏览器默认弹出窗口,因为除了更改文本消息外,无法自定义弹出窗口。

Is there any way I can hide the browser popup and show my custom popup instead. 有什么方法可以隐藏浏览器弹出窗口,而是显示我的自定义弹出窗口。

I'd really suggest you use jQuery UI for this. 我真的建议您为此使用jQuery UI。 It'll make your life much easier and has modal dialogs built into the API. 它将使您的生活更加轻松,并且在API中内置了模式对话框。 See here: http://jqueryui.com/dialog/#modal 看到这里: http : //jqueryui.com/dialog/#modal

OK, what I said before was totally wrong. 好吧,我之前所说的完全错误。 Must have been tired. 一定累了

You can't override the onbeforeunload because of the way it fires in the DOM. 您无法覆盖onbeforeunload因为它在DOM中触发的方式。 This is a good SO explaining it. 这是一个很好的解释。

How can I override the OnBeforeUnload dialog and replace it with my own? 如何覆盖OnBeforeUnload对话框并将其替换为自己的对话框?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM