I write code to open a popup in new window. I open this window for few seconds after that it will close automatically.What I want is if somebody close it before that limit of time. I will detect it and show him message. Here is code I am 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 to use window.ununload
but it is not working. can anybody please tell me how to get if somebody is going to close the browser popup?
Thanks