开发者

How to collect value of dialog box

开发者 https://www.devze.com 2023-03-12 17:36 出处:网络
I am displaying a warning dialog box on window close event. If user clicks on Cancel control stays on same page or if user clicks on Okay he get navigat开发者_如何学Goed to desired page.

I am displaying a warning dialog box on window close event. If user clicks on Cancel control stays on same page or if user clicks on Okay he get navigat开发者_如何学Goed to desired page.

I want collect the value of dialog box means whether user have clicked on Cancel or Okay.I have written following code in external JavaScript:

    $(document).ready(function()
    {
        window.onbeforeunload = askConfirm;
        
        function askConfirm()
        {
            if (flag)
            {
                // Message to be displayed in Warning.
                return "Your unsaved data will be lost.";
            }       
        } 
    }  

How can I collect the value?


<script type="text/javascript">

            window.onbeforeunload = function (evt) {

                return "Are you sure to close?";

            }

        </script>

example code

http://files.dropbox.com/u/642364/blogger/scripts/close.html

EDIT Getting the response code from the user on window close

<body onUnload = "CheckIt ()" >
...
</body>
<script>
function CheckIt ()
{
  var response = confirm ("Are you closing..");
   alert (response); // do whatever for response.

}
</script>
0

精彩评论

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