Tuesday, January 11, 2011

Unload event handler javaScript

Hey Folks !!!


this is simple javaScript to handle the Unload event.
this is the Script for that .. 
And on your HTML page declare like this.

<html>
//call the function here 
<body OnUnload="unloadHandle()">
</html>



<script language="javascript" type="text/javascript">
            function unloadHandle() {
                    try{
                               get the element which decide whether to fire the action.
                                may be hiddenfield.
                            
                                var val = document.getElementById("hfGenerateClick");
                        //ideal would be if the value != "1" then fire ..
                    if(val.value == "1")
                        alert("nice");
                    else
                        confirm("are you sure ?");
                    }
                    catch(err)
                    {alert(err.description);}
                }           
       
</script>

No comments:

Post a Comment