javascript - Avoid popup on refresh. show only when user close browser window -
i want show popup when user close browser window. but, in next code. showing popup when refresh page.
my code
<script type="text/javascript"> $(document).ready(function() { var key = true; $(window).bind('beforeunload', function(e){ if(key) homecoming confirm("do want close? log out of profile."); e.preventdefault() }); $(document).on("click","a",function() { key=false; }); }); </script>
this need.
source: open custom popup on browser window/tab close
jsfiddle: http://jsfiddle.net/sqamg/5/
var popit = true; window.onbeforeunload = function() { if(popit == true) { popit = false; homecoming "are sure want leave?"; } }
edit
use html5 web storage simulate sessions within browser. here want utilize sessionstorage rather localstorage session ends when browser window closed.
if sessionstorage variable set, not start popup, otherwise allow popup code execute.
html5 web storage: http://www.w3schools.com/html/html5_webstorage.asp
javascript jquery
No comments:
Post a Comment