Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello All,

In my project, i am using master page and if user close the browser then i want to navigate user on logout page.

Please help me to solve it.

Thanks
Posted

If the user has closed the browser how can you then navigate them? There is no way of knowing when the browser or tab has been closed as no event is raised for it. If you had done some basic research and googled this question you would have discovered that for yourself.
 
Share this answer
 
This cannot be done, at least not perfectly. Most browsers only allow you to popup a message when the user is trying to close the window. But you can't prevent the window from closing.

You can use javascript code to wireup an event:
JavaScript
$(document).ready(function () {
    window.onbeforeunload = WindowClosing;
});

function WindowClosing()
{
  return "Bye bye";
}
 
Share this answer
 
Comments
Member 8232678 19-Jan-16 4:49am    
This message will also display when you navigate from one form to another while my requirement is to display this message on on browser close event.
ZurdoDev 19-Jan-16 7:08am    
As I said, this cannot be done perfectly.

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