关闭ShowModalDialog时,重定向父窗体

问题描述

| 使用ѭ0关闭模态对话框时,如何将主页重定向到另一个网页? 我在这里关闭表单的代码
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
不起作用。     

解决方法

自从我使用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;
} 
有关更多信息,请参见online5ѭ和
showModalDialog()
的在线doco。