我编写了一个网页,其行为类似于一种信息亭:当它打开时,它会检测它是否是控制窗口。如果没有,它会加载控制窗口页面,并在新窗口中再次打开索引页面,以便检测打开器指针。然后第二个窗口包含一个链接,该链接在第三个窗口中打开任意 url。我的控制器窗口检测第二个窗口是否打开,如果有任何其他窗口聚焦,它会将那个窗口带回到前面。
这个任意网站在过程中的某个时间点打开了另一个测验窗口(不受我的网站控制),但是这个新窗口不断被推到后面,因为我的代码不断将我的第二个窗口向前推进。有什么方法可以检测第二个窗口是否打开了另一个窗口,如果是,阻止我的窗口获得焦点?
下面的代码在主页(index.php)上运行
var bypass = <?=($b==1?'true':'false')?>;
if(!bypass && !window.opener && navigator.appVersion.indexOf('Mac') != -1){
window.location = '/labs/rearWindow.php';
}
下面是我的代码,它在控制器窗口(rearWindow.php)上运行
var mainWindow = null;
var accelWindow = null;
var windowSettings = 'channelmode=yes,fullscreen=yes,height='+screen.availHeight+',width='+screen.availWidth+',left=0,top=0';
$(document).ready(function(){
window.moveTo(0,0);
window.resizeTo(10, 10);
checkWindow();
});
function checkWindow(){
if(mainWindow == null || mainWindow.closed){
// If the main window doesn't exist or it's been closed, open new window to the index
mainWindow = window.open('/labs/index.php', 'mainLabWindow', windowSettings);
if(!mainWindow){
// If the window didn't open in the satement above (usually because pop-ups are blocked), open up current window to an alternate url
window.location = '/labs/index.php?b=1';
}
}else if(mainWindow != null && !mainWindow.closed && accelWindow != null && !accelWindow.closed){
// If main window is already open and it hasn't been closed and the AR window has been opened and hasn't been closed
accelWindow.focus();
}else if(mainWindow != null && !mainWindow.closed && accelWindow != null && accelWindow.closed){
// If main window has been opened and hasn't been closed and AR window has been opened but has been closed; then go back to main window
accelWindow = null;
mainWindow.focus();
}else if(mainWindow != null && !mainWindow.closed){
// If main window has been opened and has not been closed
mainWindow.focus();
}
setTimeout(checkWindow, 500);
}
非常感谢您的帮助和反馈。
在我调用 accelWindow.focus() 的第一个 else if 中,我想检查 accelWindow 是否有任何子窗口(这意味着他们打开了测验),如果有,则不调用 accelWindow.focus()。
PS这是我的第一篇文章/问题:)