2009-05-21 14 views
0

我有一個頁面,列出上傳的附件和每個附件旁邊的圖標,打開一個彈出窗口(單擊時),以允許用戶編輯每個附件的各種附件信息。如何確保用戶在任何時候都無法打開多個彈出窗口?

我的問題是:

  1. 如何確保用戶可以在任何一個時間

  2. 當用戶試圖打開另一個彈出窗口只能打開一個彈出窗口,一個警報會彈出並告訴他/她不允許打開多個窗口。

回答

2

您可以使用「處理」的窗口,檢查它是否是開放與否,這裏是一個示例:

var vWin = null; 
var msWindowUsedMessage = "A previous action was not completed.\nClose the window and try again."; 

function IsWindowUsed(oWindowToCheck) { 
    if (!oWindowToCheck.closed && oWindowToCheck.location) { 
     alert(msWindowUsedMessage); 
     oWindowToCheck.focus(); 
     return true; 
    } 
    return false; 
} 
function Open_New_Window(sUrl, sTitle, sParams) { 
    var winLeft = top.screenLeft + 50; 
    var winTop = top.screenTop + 50; 
    var oWindowHandle = window.open(sUrl, "", sParams + ",toolbar=no,top=" + winTop + ",left=" + winLeft); 
    oWindowHandle.opener = self; 
    return oWindowHandle; 
} 

function Add() { 
    if (IsWindowUsed(vWin)){ 
     return; 
    } 
    var sParams = "width=380,height=10,status=no,resizable=yes"; 
    var sUrl = "add.aspx"; 
    vWin = Open_New_Window(sUrl, 'Add', sParams); 
} 
0

爲什麼不製作每個彈出窗口模式,以便在與主頁面進行交互之前必須將其解除。這對於jQuery Dialog plugin來說很容易,但你也可以用一些javascript/css魔法來製作你自己的。

3

當你打開它時給彈出一個名字。這將強制任何後續點擊在同一個彈出窗口中打開。然後,您可以實現window.unload事件,以防止用戶從當前正在保存的頁面導航離開。

如果您使用的是jQuery,但我建議您使用ui.dialog來提供頁面中的功能。然後,您還將一次強制用戶編輯一個。

0

創建一個cookie或全局(基於您的需要的客戶端或服務器端)標誌並檢查每次觸發彈出時是否設置它。

3

當你創建一個新的彈出窗口,設置變量指向新的窗口然後檢查它是否已關閉:

var currentPopup = null; 

function openPopup(){ 

    //test that we have either not opened a popup or have closed it. 
    //references to closed windows don't disapear, but have their closed property set to true. 
    if(!currentPopup || currentPopup.closed){ 

     //set the new currentPopup variable to reference the new window. 
     currentPopup = window.open(...); 
    } 
    else{ 
     //A window is open! Display error message. 
     //for the best user experience use a nice way to display the message as opposed to using an alert(); 

    } 
} 
相關問題