每当用户按下F2键时,我都会在下面打开一个新窗口。
$(document).bind('keyup', function(e){
if(e.which==113) {
window.open('newPage.htm','_blank','','false');
}
});
现在,我想阻止用户打开一个新窗口,而前一个窗口仍然打开。我怎么能点到它?
答案 0 :(得分:2)
var opened = null;
$(document).bind('keyup', function(e){
if (e.which == 113 && (!opened || !opened.window))
opened = window.open('newPage.htm','_blank','','false');
});
答案 1 :(得分:0)
你可以试试这个..
var windowOpened=false;
$(document).bind('keyup', function(e){
if(e.which==113 && !windowOpened) {
window.open('newPage.htm','_blank','','false');
windowOpened=true;
}
});
In the newPage.htm add code to make windowOpened=false when u close that window.
< html>
< head>
< title>newPage.htm< /title>
<script>
function setFalse()
{
opener.windowOpened = false;
self.close();
return false;
}
</script>
< /head>
< body onbeforeunload="setFalse()">
< /body>
< /html>
答案 2 :(得分:0)
为您的窗口命名,如
var mywindow = window.open("foo.html","windowName");
然后你可以通过
检查窗口是否关闭if (mywindow.closed) { ... }
答案 3 :(得分:0)
当窗户关闭时,window.document会发生什么?它是否为空,也许您可以通过null检查它。
var popupWindow;
$(document).bind('keyup', function(e){
if(e.which==113 && (!popupWindow || !popupWindow.document)) {
popupWindow = window.open('newPage.htm','_blank','','false');
}
});