Click here to Skip to main content
15,942,154 members
Please Sign up or sign in to vote.
5.00/5 (1 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


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

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


Thank You in Advance

1 solution

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
Share this answer
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 :
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900