2010-11-09 74 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

相關問題