【问题标题】:Closing a particular child window when parent window user logs out父窗口用户注销时关闭特定子窗口
【发布时间】:2015-12-25 13:56:13
【问题描述】:

我有一个网站,点击按钮将在子窗口中打开用户。

 var childWindow=window.open('<?=$this->config->item('base_url').'after_login/portfolio' ?>', 'bypassed_user_window','height=' + screen.height + ',width=' + screen.width + ',resizable=yes,scrollbars=yes,toolbar=yes,menubar=yes,location=yes');

现在,我想在父窗口用户注销时关闭这个子窗口。 我正在使用 Codeigniter。 如果我在控制器中给出&lt;script&gt;childWindow.close();&lt;/script&gt;,它会给出未定义的childWindow,这只是预期的。那么现在关闭窗口的方法是什么。谢谢!

【问题讨论】:

    标签: javascript php codeigniter window.open


    【解决方案1】:

    childWindow 确实是undefined。所以,为了实现你想要做的事情,你需要一个对这个窗口对象的引用。你可以试试这样的:

    <script type="text/javascript">
        var childWindow = window.open('', 'bypassed_user_window');
    
        if (childWindow !== null) {
            childWindow.close();
        }
    </script>
    

    首先,我不能 100% 确定这是否适用于所有浏览器,但如果您指定与以前相同的名称,您应该得到相同的窗口。如果您返回对该对象的相同引用,则取决于原始窗口和打开的窗口中使用的域/端口。如果关闭此窗口不起作用,您可以将此窗口发送到您关闭窗口本身的另一个 URL。欲了解更多信息,请参阅https://developer.mozilla.org/en-US/docs/Web/API/Window/open(并查看本页提到的同源政策,以检查您是否可以做您想做的事)。

    【讨论】:

      猜你喜欢
      • 2012-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 2011-01-19
      相关资源
      最近更新 更多