简体   繁体   English

导航网站时保留弹出窗口 window

[英]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.

相关问题 即使在弹出窗口中导航到新页面时,也要保持指向回调的指针 - Keep a pointer to a callback even when navigating to a new page in a popup window 当网站开放但第一次打开时,PHp会打开弹出窗口 - PHp open popup window when website is open but only first time 网站上会打开一个奇怪的弹出窗口 - a strange popup window opens in website 使用Colorbox在弹出窗口中加载外部网站 - Loading external website in popup window using Colorbox 在新标签/窗口/弹出窗口中打开外部网站 - Opening an external website in a new tab/window/popup 从页面导航时如何删除默认的“您确定”弹出窗口 - How to remove the default 'Are you sure' popup when navigating from a page Magento在离开一页结帐时如何保留访客帐单地址详细信息 - Magento how to retain guest billing address details when navigating away from one-page checkout 导航到新页面时使用本地存储保留 state 个单选按钮 - Using local storage to retain state of radio buttons when navigating to a new page 浏览网站时如何维护选定的 CSS 表? - How to maintain the selected CSS sheet when navigating through website? 导航离开然后返回时在单页网站上加载 javascript 时出现问题 - Issues loading in javascript on single page website when navigating away and then returning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM