2012-04-18 148 views
0

我有一個使用Java Script管理站點的Java項目。我有一個功能來打開幫助對話框彈出窗口。當我刷新主頁面時,一個彈出窗口不會關閉,它仍然是打開的。我有一個保護,你可以幫助打開2個窗口,但它與處理程序(helpWnd)一起工作,在刷新主頁時它會丟失。處理程序在刷新父窗口後彈出窗口

對不起,我的英文; )

var helpWnd = null; 
// Open help dialog with url from recived helpId 
function openHelpDialog(helpId, height, width, title) { 
    var url; 
    if(helpId == "contact") { 
     url = "help/contact.html"; 
    } else { 
     var regularExpression = /[a-zA-Z][a-zA-Z][a-zA-Z][0-9][0-9][0-9][0-9]/; 
     if(helpWnd!=null) { 
      helpWnd.close(); 
     } 
     url = "help/index.html?"+helpId.toLowerCase()+".html"; 
     if(!regularExpression.test(helpId)) { 
      url = "help/index.html"; 
     } 
    } 
    helpWnd = window.open(url, title, 'width=1000, height=600, menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no'); 
} 

//this refresh main page 
function changeRole(roleName,redirectUrl) { 
    dojo.xhrPost({ 
     content: { 
      role: roleName 
     }, 
     handleAs: "json", 
     sync: true, 
     url: 'someUrl.npi', 
     load: function (response) { 
      dojo.cookie(response.cookieHash, response.role, {expires : response.cookieExpiryTime}); 
      document.location.href = redirectUrl; 
     } 
    }); 
} 

回答

0

在許多情況下打開窗戶被認爲是有害的,因爲您可能已經發現了自己。

更好的選擇是使用模態對話框與JavaScript,這本質上是在同一頁面中的分層對話框。我不是一個Dojo專家,但我很快找到了Google的文檔(http://dojotoolkit.org/reference-guide/1.7/dijit/Dialog.html)

無論如何,如果您仍然想要打開窗口如果你確定它的重點,你可能會得到更好的行爲。看看這裏:http://www.quirksmode.org/js/popup.html