在window.onbeforeunload对话框中选择拦截 [英] Intercept selection in window.onbeforeunload dialog
问题描述
在我的Web应用程序中,如果用户离开当前页面时未保存任何形式的更改,则会打开一个弹出窗口来提醒他。
in my web application if the user leaves the current page without having saved changes in the form a pop up window is opened to alert him about that.
对于弹出窗口,我使用从代码隐藏(C#)注入的一些脚本代码:
For the pop up I use some scripts code injected from codebehind (C#):
var Confirm = true;
window.onbeforeunload = confirmClose;
function confirmClose()
{
if (!Confirm) return;
if(/*CHECK CHANGE CONDITION IS TRUE*/)
{ return " + WARN_message + "; }
}
我需要拦截用户是否单击取消或确定按钮。
I would need to intercept whether the user click on cancel or ok button.
我尝试过:
var button_pressed = window.onbeforeunload = confirmClose;
但它始终返回true。
But it returns always true.
如何获取按下了哪个按钮?
谢谢
How can get which button was pressed? Thanks
推荐答案
不可能。没有与按钮关联的事件。
您可能能够做的是通过在onbeforeunload的页面中设置值或cookie来查看用户是否回来,并在一段时间后测试是否存在
Not possible. There is no event associated with the buttons. What you might be able to do was to see if the user came back by setting a value or perhaps a cookie in the page in the onbeforeunload and test if it is there after some time has passed
,但查看重复的如何知道用户是否在onbeforeunload对话框上单击了Java取消?
这篇关于在window.onbeforeunload对话框中选择拦截的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!