jquery - javascript on window close event -
i detecting if user of site closes window/tab or changes url.
i using follwoing code, works perfectly:
var validnavigation = false; function endsession() { // browser or broswer tab closed // sth here ... alert("bye"); } function wireupevents() { window.onbeforeunload = function() { if (!validnavigation) { endsession(); } } // attach event keypress exclude f5 refresh $(document).bind('keypress', function(e) { if (e.keycode == 116){ validnavigation = true; } }); // attach event click links in page $("a").bind("click", function() { validnavigation = true; }); // attach event submit forms in page $("form").bind("submit", function() { validnavigation = true; }); // attach event click inputs in page $("input[type=submit]").bind("click", function() { validnavigation = true; }); } $(document).ready(function() { wireupevents(); }); my problem change event alert overlay. have setup hidden div overlay , replaced alert in above code with:
$('.overlay').css('display','block'); this no longer works, there nothing within div user stay on page. (the user doesn't have click button within alert)
any suggestions on how can around this?
cheers, dan
the window close event fired last event. therefore no other events fired after it.
you can use beforeunload event jquery, show overlay on screen.
the following link help: link
Comments
Post a Comment