Click here to Skip to main content
14,975,411 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello to all
I need coding to create confirm alert message when user clicks a browser close button..........

Javascript coding is more helpful to me....

Can anyone help me.
Posted

   
try this

JavaScript
window.onunload = function () {
           var r = confirm( "Press a button!" )
           if ( r == true ) {
               alert( "You pressed OK!" )
           }
           else {
               alert( "You pressed Cancel!" )
           }

       };


see reference

window.onunload
   
v2
Comments
vivekx2 5-Apr-12 1:53am
   
If we using unload function the alert comes for each and every time when browser get loading....
I just need a alert when user clicks the browser/tab close button....
Bojjaiah 5-Apr-12 2:18am
   
now updated see link
vivekx2 5-Apr-12 5:50am
   
Sorry its not working......
Use Following code
HTML
<input type="submit" value="Show" onclick="if(confirm('Are you sure ,You want to delete this?')){return true;}else{return false;}" />
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900