Click here to Skip to main content
14,304,866 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi to all
i want to show a alert to users after close browser window.

you may say that use of unload or onunload event
but this event fire when my submit button in my form is clicked
and this alert show to them when form is submitted!!!!!
i want to show alert just close from browser.
how can i do this
thanks for any help
Posted
Updated 11-Mar-14 5:01am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

you can use following script as 


var confirmOnPageExit = function (e) {
     // If we haven't been passed the event get the window.event
     e = e || window.event;

     var message = 'Your information will be lost. Are you sure ?';

     // For IE6-8 and Firefox prior to version 4
     if (e) {
         e.returnValue = message;
     }

     // For Chrome, Safari, IE8+ and Opera 12+
     return message;
 };


 // Turn it on - assign the function that returns the string
 window.onbeforeunload = confirmOnPageExit;



DeActivate on Submit button


<input type="submit" onclick="window.onbeforeunload = null; " value="Save"  />



For the new changes in input fields


$('input').blur(function () {

      window.onbeforeunload = confirmOnPageExit;
  });
   
Comments
mhd.sbt 11-Mar-14 15:39pm
   
ok
thanks for your answer.
this way just work for the show an alert
is there a way that use this way for call a public method in "confirmonpageExit" function
for example call a method like below in this function :
<%RemoveWorkSpace();%>
i want to call a public method when user click the close button in browser.
thanks for your time.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100