[英]retain popup window when navigating website
The following code produces a javascript popup when a page is loaded and then closes the popup window when the parent window is closed.以下代码在加载页面时生成 javascript 弹出窗口,然后在关闭父 window 时关闭弹出窗口 window。
<script language="JavaScript">
var player;
function load() {
player = window.open('http://www.google.com','player','height=320,width=320,scrollbars,resizable');
}
function unload() {
player.close();
}
window.onload = load;
window.onunload = unload;
</script>
This is working fine, however it closes the popup window when switching pages on the site.这工作正常,但是在网站上切换页面时它会关闭弹出窗口 window。 Is there any way this can be altered to keep the popup window until the actual URL/Site window is closed?
有什么方法可以改变它以保持弹出 window 直到实际的 URL/站点 window 关闭?
I think you have to check the status of the parent window from the child, instead of vice-versa.我认为您必须从孩子那里检查父 window 的状态,而不是反之亦然。
This code has not been tested, but I'm taking a stab at the concept:此代码尚未经过测试,但我正在尝试这个概念:
window.opener.onunload =
setTimeout(
function(){
if (!window.opener) self.close();
}, 1000);
Short answer is NO, the only way to hook into the event that closes the window is onunload
, which fires when the document is unloaded (like when you navigate to another page).简短的回答是否定的,唯一的方法是挂钩关闭 window 的事件是
onunload
,它在文档被卸载时触发(比如当你导航到另一个页面时)。
Maybe you could check window.opener
on the popup (with a timer, or onfocus), to check if the window that originated the popup still exists, then close the popup if it doesn't.也许您可以检查弹出窗口上的
window.opener
(使用计时器或 onfocus),以检查产生弹出窗口的 window 是否仍然存在,如果不存在则关闭弹出窗口。
This may help you:这可能会帮助您:
<script language="Javascript">
var player;
function load() {
player = window.open('http://www.google.com','player','height=320,width=320,scrollbars,resizable');
}
function unload() {
if (!(window.location.equals('http://yourSiteName.com'))) {
player.close();
}
}
window.onload = load();
window.onunload = unload();
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.