2011-05-24 19 views
0

當我使用showModalDialog關閉模態對話框時,如何將我的主頁重定向到另一個網頁?當ShowModalDialog關閉時重定向父表格

我這裏有我的關閉表單代碼:

function Msg() 
{ 
    parent.window.opener.location.href = 'MyRequirements.aspx'; 
    window.close(); 
} 

這裏是我打開的模態對話框代碼:

function Go() 
{ 
    var model= document.getElementById("cboModel").value; 
    var variant= document.getElementById("cboVariant").value; 
    var color = document.getElementById("cboColor").value; 
    var code = document.getElementById("txtCode").value; 
    window.showModalDialog("MesgeBox.aspx?model=" + model + 
     "&variant=" + variant + "&color=" + color + "&code=" + code + 
     "","","dialogHeight: 100px; dialogWidth: 80px; edge: Raised;help: No; resizable: No; status: No; center: Yes; scrollbars: No;") 
} 

opener.location不工作。

回答

1

這是一個很長一段時間,因爲我用在showModalDialog,但假設你想重定向到是可變的URL,需要從孩子的模態對話框中設置我覺得這樣的事情應該工作:

// Msg() is on child dialog 
function Msg() { 
    window.returnValue = 'MyRequirements.aspx'; 
    window.close(); 
} 

// Go() is on parent window 
function Go() { 
    // your intialisation 
    var newLocation = window.showModalDialog(/*your params*/); 
    if (newLocation != "") 
     window.location.href = newLocation; 
} 

欲瞭解更多信息,請參閱returnValueshowModalDialog()的在線doco。

+0

謝謝:)讚賞 – 2011-07-08 08:45:15