2012-09-10 42 views
2

所以我建立一個「喜歡」按鈕,但我有一個小問題在用戶登錄在通過小窗口,用戶必須刷新整個頁面後。我希望它檢查窗口是否關閉,然後刷新iframe。所以我有這個代碼來打開彈出窗口,我一直在看這個帖子尋求幫助,但它沒有那麼大的幫助。 Check if a popup window is closed檢查,如果窗口已經關閉,裏面的iframe

function grubber_highlight() 
      {   
        var popup = window.open("http://www.grubber.co.nz/login/", "newwindow", config="height=600,width=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no"); 
         var windowloc = document.URL; 
         var windowlocation = (windowloc + "&highlight=t"); 
         window.location = windowlocation; 
         if (popup) { 
          popup.onclose = function() { alert("closed"); } 
         }     
      } 

我有這樣的代碼來檢查,如果窗口已經關閉,然後提醒我,它一直

    if (popup) { 
         popup.onclose = function() { alert("closed"); } 
        } 

小窗口放在這裏 http://www.grubber.co.nz/login/ 如果任何人想的就知道了。

我也希望它能夠在大多數瀏覽器中運行較新的是IE8

編輯 我GOOGLE了,但更深層次的發現onunload的它的工作原理就關門,但它也激發了當我打開該窗口還...

問題

在關閉窗口如何檢測,然後刷新的iframe

+0

我不太明白什麼你問。你的問題是:「如何替換'alert(」closed「);'用其他代碼刷新iframe?」 – nnnnnn

+0

沒有當小彈出關閉 – ryanc1256

+0

您發佈表明,你已經* *知道當小彈出關閉如何檢測代碼如何檢測。畢竟,當彈出窗口關閉時,您正在運行警報代碼。 –

回答

1

好,謝謝傢伙,但我去我想與onunload的事件回答

 var popup = window.open("http://www.grubber.co.nz/login/", "newwindow", config="height=600,width=800, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, directories=no, status=no"); 
var windowloc = document.URL; 
var windowlocation = (windowloc + "&highlight=t"); 
window.location = windowlocation; 
var e = 0; 
if (popup) { 
    popup.onunload = function() { 
     if (e == 1) 
     { 
     //this will reload the iframe 
     alert("closed"); 
     } 
     else 
     { 
      //this will be when the pop-up gets created 
     e++;          
     }       
} 
+0

看,那是我的問題,比如我的更新部分 – Talha

+0

@Talha揭掉,它並沒有真正的幫助,但它確實幫我找到onunload事件 – ryanc1256

2

認爲這是怎麼彈出打開:

win = window.open(...); 

然後,你應該反覆檢查彈出窗口關閉。

var timer, win; 
function polling(){ 
if (win && win.closed) { 
    clearInterval(timer); 
    alert('popup window is closed.'); 
} 
} 
timer = setInterval('polling()',100); 

更新: 另一種技術討論here

+0

對不起,我不認爲任何人正想回答讓我有種與onunload的事說幹就幹,得到了回答 – ryanc1256

+0

@ Ryanc1256如果你找到答案,也可以與我們分享 – Talha

+0

是的,我做到了,就在這時, – ryanc1256