2010-11-09 67 views
0

如何修改此操作以便检查弹出式窗口是否已打开?检查弹出式窗口是否已打开

function popUp(URL) { 
    day = new Date(); 
    id = day.getTime(); 
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100');"); 
} 

/////////////编辑NO2

var options = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100";

var popup = window.open(URL, "popup", options);

function popUp(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100');"); }

我的JS调用

<a id="floating_link" href="javascript:popUp('MyPage.html')">Player</a>

+0

noooooooooooo !!!!!!!!!!!!! eval #ftf! – 2010-11-09 18:50:25

+0

它不是一个http回调,它只是使用局部变量。这看起来像eval的一个非常安全的使用。放松。 – 2010-11-09 18:51:52

+0

@ Travis,是的,我看到了,但仍然... – 2010-11-09 18:53:48

回答

0

它将使用同一个窗口一个锚标记做到这一点我的回答是将this这个问题关联到这里。

请检查以下代码。

您可以使用onbeforeunload在窗口卸载之前获得回调。

要检查是否这是由于window.close做到这一点

setTimeout(function(){ 
     if(anc.closed) console.log('closed'); 
     else console.log('refreshed'); 
    },1000); // to check after the window closed 

全码

var anc = window.open('https://stackoverflow.com'); 

var anc.onbeforeunload = function() { // called before closing the window. 

    setTimeout(function() { 
    if (anc.closed) console.log('closed'); 
    else console.log('refreshed'); 
    }, 1000); // to check after the window closed 

} 
+0

真棒小费天底,谢谢你! – detonate 2017-10-25 05:13:59

1

使用的窗口,这是窗口的名称相同id,如果存在重复使用它。

http://www.w3schools.com/jsref/met_win_open.asp

var options = "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=350,height=100"; 
var popup = window.open(URL, "popup", options); 

要与你刚才设置的target

如果设置一个锚标记的目标target="myopup"如果存在

+0

在页面顶部粘贴最新的代码编辑 – detonate 2010-11-09 19:36:00

+0

您的最新修订是否有效? – hunter 2010-11-10 13:39:23

+0

没有不能使它工作。你会有另一个建议猎人。如果主页上的按钮可以切换也会很好... – detonate 2010-11-11 04:10:11