I am opening multiple windows with window.open, on click. I want to know, 10 seconds later, which window is still open. Is there a way to uniquely identify a window I just open?
I use the code below, but if I open a window, close it, then open another one, the code will throw the alert "window still open" twice. I understand why, but is there an easy way to identify the window, so I can check var_win.closed for the window I want, and not for the one open last?
<div class="get_link" data-url="http://www.yahoo.com">Window 1</div>
<div class="get_link" data-url="http://www.yahoo.com">Window 2</div>
<div class="get_link" data-url="http://www.google.com">Window 3</div>
<div class="get_link" data-url="http://www.space.com">Window 4</div>
Javascript:
jQuery(document).ready(function(e) {
e( "body" ).on( "click", ".get_link", function(t) {
t.preventDefault();
var n = e(this);
var u = n.data("url");
var_win=window.open(u);
function checkwindow(){
if (!var_win.closed)
alert( "window still open");
else
alert ("window closed");
}
setTimeout(checkwindow, 10000);
return false
})
})