javascript - how to check browser popup is going to close -


i write code open popup in new window. open window few seconds after close automatically.what want if close before limit of time. detect , show him message. here code using

$(document).ready(function() {      var mywindow;     $("#idview").click(function() {         var vidurl = $('#vurl').val();         counter();         mywindow = window.open(vidurl, "popupwindow", "width=600, height=400, scrollbars=yes");      });      function counter() {         var n = $('.c').attr('id');         var c = n;         $('.c').text(c);         setinterval(function() {             c++;             if (c <= 41) {                 $('.c').text(c);             }             if (c == 41) {                 $('.c').text(n);             }         }, 1000);     }        setinterval(function() {         mywindow.close();     }, 45000);      window.onbeforeunload = closingcode; function closingcode(){    alert('hitme');    return null; }   }); 

i try use window.ununload not working. can please tell me how if going close browser popup?

thanks

you can use onbeforeunload :

 window.onbeforeunload = function (e) {   var e = e || window.event;  }; 

more reference : https://developer.mozilla.org/en-us/docs/web/api/windoweventhandlers/onbeforeunload

even possible duplicate of : javascript detect browser close tab/close browser


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -