将一个Flash播放器弹出到一个单独的弹出式浏览器窗口中。在源页面上,Flash播放器只显示当前弹出的消息。
现在,如果用户离开源页面(到同一域上的另一个页面),我如何获得对弹出窗口的引用,或者只是检测它是否打开(在新页面上使用javascript)?
答案 0 :(得分:0)
想出来了。必须在弹出的窗口中有一个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>