Click here to Skip to main content
14,336,321 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi ,
This below code working Fine but this code execute every event But i want when click the browser close Button this below code execute ... Give the suggestions



<script>

       window.CloseEvent("beforeunload", function (e) {

           var confirmationMessage = "Vamsi Vakati";
           (e || window.event).returnValue = confirmationMessage; 
           return confirmationMessage;                           

       });</script>




Thank You in Advance
Posted

1 solution

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

Solution 1

Please try is as below.

Note: This is just a sample.Adjust it according to your app.
window.addEventListener("beforeunload", function (e) {
  var confirmationMessage = "\o/";

  (e || window.event).returnValue = confirmationMessage;     //Gecko + IE
  return confirmationMessage;                                //Webkit, Safari, Chrome etc.
});


Check here for more info : beforeunload
   
Comments
vakativamsi 17-Apr-14 3:27am
   
Thank you for your Reply .This above Both are working Same
Sampath Lokuge 17-Apr-14 3:39am
   
Aha..Check this link : http://stackoverflow.com/questions/3888902/javascript-detect-browser-close-tab-close-browser
vakativamsi 17-Apr-14 3:50am
   
i am not getting that answer ... my aim is only when click the browser close button the above code is executed ...... But Now all the time that code executing
Member 12363241 2-Mar-16 1:14am
   
I am facing the same issue. If you got the solution Please help me.

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