Javascript仅打开弹出窗口一次,关闭事件
我有下面的代码和一个函数: 如果弹出窗口关闭,警报框将显示 但我想弹出窗口只打开一次。我的意思是,如果弹出窗口已经存在,它将不会创建另一个弹出窗口,否则它将只关注已存在的窗口Javascript仅打开弹出窗口一次,关闭事件,javascript,popup,Javascript,Popup,我有下面的代码和一个函数: 如果弹出窗口关闭,警报框将显示 但我想弹出窗口只打开一次。我的意思是,如果弹出窗口已经存在,它将不会创建另一个弹出窗口,否则它将只关注已存在的窗口 function PopupCenter() { var win = window.open('https://www.facebook.com/sharer/sharer.php?u=<?php echo $bloglink; ?>', 'googl_e','width=800,height=400,
function PopupCenter() {
var win = window.open('https://www.facebook.com/sharer/sharer.php?u=<?php echo $bloglink; ?>', 'googl_e','width=800,height=400,status=0,toolbar=0,top=20,left=20');
var timer = setInterval(function() {
if(win.closed) {
clearInterval(timer);
alert("The video is ready to play.");
$(".bg-lock").fadeOut();
}
}, 1000);
}
函数PopupCenter(){
var win=window.open('https://www.facebook.com/sharer/sharer.php?u='、'googl_e'、'width=800,height=400,status=0,toolbar=0,top=20,left=20');
var timer=setInterval(函数(){
如果(赢.闭){
清除间隔(计时器);
警报(“视频已准备好播放”);
$(“.bg lock”).fadeOut();
}
}, 1000);
}
我认为全球风险值正是您所需要的。更新:我在全局变量和窗口onforeUnload事件方面遇到一些问题。因此,我对全局var使用jquery,并使用计时器进行检查
我假设您使用jquery(因为我看到了fadeOut方法),所以我使用$.myWin作为全局变量
function PopupCenter() {
if ($.myWin == undefined) {
$.myWin = window.open('https://google.com');
var timer = setInterval(function() {
if (($.myWin != undefined) && ($.myWin.closed)) {
clearInterval(timer);
alert("The video is ready to play.");
$(".bg-lock").fadeOut();
}
}, 1000);
}
}
抱歉我的懒惰测试:D,我已经更新了我的答案并测试了它。