当用户尝试重定向到其他页面或关闭浏览器时,如何显示警报消息 [英] How Do I Show Alert Message When User Attempts To Redirect To Other Page Or Close Browser

查看:104
本文介绍了当用户尝试重定向到其他页面或关闭浏览器时,如何显示警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,当用户点击浏览器关闭按钮或网页的其他按钮时,必须显示一条消息警告所有输入的数据都将丢失。你确定??..在谷歌上,建议使用javascript的window.onbeforeunload事件......但是窗口。不会在我的IDE上显示onbeforeunloadthod。我正在使用visual studio 2010 .net framework 4.0和script type =text / javascript。任何帮助?任何替代方法来实现这一点..

i am developing an application where when a user clicks on a browser close button or other button of a webpage, a message must be shown of warning "All entered data will be lost. are you sure??".. on google, it is suggested to use window.onbeforeunload event of javascript... but window. doesnot shows onbeforeunloadthod on my IDE. i am using visual studio 2010 .net framework 4.0 and script type="text/javascript". any help?? any alternative way to accomplish this..

推荐答案

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



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

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



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

—SA


这篇关于当用户尝试重定向到其他页面或关闭浏览器时,如何显示警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆