I want to capture browser close event using javascript. I googled but I am not getting any solution anywhere,below is my code where I have handled anchor, Form Submit and Submit button on onbeforeunload.
<script> var validNavigation = false; function wireUpEvents() { window.onbeforeunload = function() { if (!validNavigation) { // invalidate session } } // Attach the event keypress to exclude the F5 refresh $(document).bind('keydown', function(e) { if (e.keyCode == 116){ validNavigation = true; } }); // Attach the event click for all links in the page $("a").bind("click", function() { validNavigation = true; }); // Attach the event submit for all forms in the page $("form").bind("submit", function() { validNavigation = true; }); // Attach the event click for all inputs in the page $("input[type=submit]").bind("click", function() { validNavigation = true; }); } // Wire up the events as soon as the DOM tree is ready $(document).ready(function() { wireUpEvents(); }); </script> Is there any way I can capture browser close button event, I have seen developers using X and Y axis but that is not recommended most of developers.
Thanks..
onbeforeunload, when the page is unloaded (right before it's either closed or reloaded). Why does that not work for you? (Also, what are you really trying to do?)