Wednesday, April 23, 2008

Show confirm message during browser window close.


Here is the code that will show a confirmation message if user want to close browser window/close.




<form name="form1" id="form1">
     <input type="submit" name="btn1" value="Submit1" onclick="return chk();">
 </form>
 <form name="form2" id="form2">
     <input type="submit" name="btn1" value="Submit2">
</form>
<script language="javascript">
    var fillout = false;
    window.onbeforeunload=function verifyclose() {
        var undefined;
        var msg;
        if (document.forms[0] == undefined)
            return;
        if (!fillout) {
            msg = " Do you want quit/close this window?";
        }
        return msg;
    };   
   
    function chk() {
        return false;   
    }
 </script>

No comments:

Post a Comment