检查用户是否单击了“确定".对于"onbeforeunload事件" [英] Check if User has clicked "Ok" for "onbeforeunload event"
问题描述
我正在检查用户何时关闭浏览器窗口,如果他说确定",我如何触发某些操作,例如打开另一个窗口或保存表单.如果他选择取消",则它应该留在同一页面上(现在正在工作).请分享一些有关如何解决此问题的想法
I am checking when the user closes the browser window, if he says ok, how i do I trigger some action, like opening another window or saving a form. If he chooses "cancel", it should stay in the same page (which is working now). pls share some idea on how to approach this issue
推荐答案
您无法对用户单击离开此页面"按钮做出反应.这是由浏览器设计的:如果用户想离开,请让他离开.
You cannot react to the user clicking on the "Leave this page" button. This is by design of the browser: if the user wants to leave, let him go.
如果用户选择取消,则可以尝试在此类似问题的答案中找到的技术来执行一些自定义操作诸如保存更改之类的代码.
If the user chooses to cancel, you can try a technique found in this answer to similar question to execute some custom code like saving changes or the like.
这篇关于检查用户是否单击了“确定".对于"onbeforeunload事件"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!