gpt4 book ai didi

javascript - javascript 可以检测一个窗口是否打开了另一个窗口吗?

转载 作者:行者123 更新时间:2023-12-02 20:38:09 24 4
gpt4 key购买 nike

我编写了一个网页,其行为类似于一种信息亭:当它打开时,它会检测它是否是控制窗口。如果没有,它将加载控制窗口页面,并在新窗口中再次打开索引页面,以便它可以检测打开器指针。第二个窗口包含一个链接,可在第三个窗口中打开任意 URL。我的 Controller 窗口检测第二个窗口是否打开,如果有任何其他窗口获得焦点,它将将该窗口带回到前面。

这个任意网站在该过程中的某个时刻会打开另一个测验窗口(不受我的网站控制),但这个新窗口不断被推到后面,因为我的代码不断将第二个窗口向前推进。有没有任何方法可以检测第二个窗口是否打开了另一个窗口,如果是,则阻止我的窗口获得焦点?

下面的代码在主页(index.php)上运行

var bypass = <?=($b==1?'true':'false')?>;
if(!bypass && !window.opener && navigator.appVersion.indexOf('Mac') != -1){
window.location = '/labs/rearWindow.php';
}

下面是我的代码,它在 Controller 窗口(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);
}

非常感谢您的帮助和反馈。

在第一个 else if 中,我调用 accelWindow.focus() ,我想检查 accelWindow 是否有任何子窗口(这意味着它们打开了测验),如果有,则不调用 accelWindow.focus( )。

PS 这是我的第一篇文章/问题:)

最佳答案

您可以在同一浏览器窗口内、同一应用程序内的某种框架中显示这些“窗口”内容。您可以使用 lightbox。使用基于浏览器的应用程序可以处理多个窗口似乎很不舒服。

关于javascript - javascript 可以检测一个窗口是否打开了另一个窗口吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14610904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com