且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

当用户尝试重定向到其他页面或关闭浏览器时,如何显示警报消息

更新时间:2022-11-18 14:11:50

此功能正常工作,与Visual Studio无关。在你的问题中,你是混合了一些东西,我不知道为什么。



另外,你真的不需要 onebeforeunload ,也许你可以使用 onunload 代替。请参阅:

http:/ /msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx [ ^ ]。



如果您需要阻止用户从您的页面导航,那么您只需要 (顺便说一句,这通常不是很好,但您可以要求用户确认并仍然允许如果确认,则离开页面)。另见此讨论: http://***.com/questions/3775566/javascript-question-onbeforeunload -or-onunload [ ^ ]。



-SA
This functionality just works and is not related to Visual Studio whatsoever. In your question, you are mixing somethings up, I don't know why.

Also, it is not apparent that you really need onebeforeunload, maybe you can use onunload instead. Please see:
http://msdn.microsoft.com/en-us/library/ie/ms536907%28v=vs.85%29.aspx[^].

You only needs if you need to stop the user from navigating from your page (which is usually not very nice, by the way, but you can ask users confirmation and still allow to leave the page if the confirmation is given). See also this discussion: http://***.com/questions/3775566/javascript-question-onbeforeunload-or-onunload[^].

—SA