获取弹出窗口 页面更改后

Get Popup window After page change

本文关键字:窗口 获取      更新时间:2023-09-26

有一个闪存播放器,它会弹出到一个单独的弹出式浏览器窗口中。在源页面上,Flash 播放器仅显示一条消息,指出它当前已弹出。

现在,如果用户离开源页面(导航到同一域上的另一个页面),我如何获取对弹出窗口的引用或仅检测它是否打开(在新页面上使用 javascript)?

通了。必须在弹出的窗口中有一个javascript计时器,该计时器尝试在父窗口中执行一个函数,如果存在,则只会隐藏播放器。

弹出窗口脚本

<script>
    if(window.opener!=null)
        setTimeout("popCheck();",2000);
    function popCheck()
    {
        //Use try catch to prevent premission denied msgs in 
        //case parent window is on different domain
        try
        {
            window.opener.setPoppedOut();
        }
        catch(e)
        {
        }
        //Check Every 2 seconds
        setTimeout("popCheck();",2000);
    }
    window.onbeforeunload = function()
    {
        //Used to facilitate popin on window close
        if(window.opener!=null)
        {
            try
            {
                window.opener.setPoppedIn();
            }
            catch(e)
            {
            }
        }
    }
</script>

父窗口脚本

<script>
    //Save the previous contents so that we can restore them later.
    window.popoutContent = document.getElementById("popoutContent").innerHTML;
    function setPoppedOut()
    {
        document.getElementById("popoutContent").innerHTML = "Player is Popped Out";
    }
    function setPoppedIn()
    {
        document.getElementById("popoutContent").innerHTML = window.popoutContent;
    }
</script>