开发者

Intercept selection in window.onbeforeunload dialog

开发者 https://www.devze.com 2023-03-05 14:38 出处:网络
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 abo开发者_高级运维ut that.

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 abo开发者_高级运维ut that.

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.

I tried like:

var button_pressed = window.onbeforeunload = confirmClose;

But it returns always true.

How can get which button was pressed? Thanks


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

but see the duplicate Way to know if user clicked Cancel on a Javascript onbeforeunload Dialog?

0

精彩评论

暂无评论...
验证码 换一张
取 消