在模态窗口中,如果直接用document.location来刷新页面,会弹出一个新的窗口。解决的办法有很多种。
善于思考人的就会发现,我点击链接或按纽就可以刷新,程序是不是也可以模拟呢。当然可以。
这里给出几种常用办法。
1.post方式刷新。
这个比较容易。
首先,页面中<head></head>中必须有
<
base
target
="_self"
></
base
>
否则提交页面会新开一个窗口。
至于代码就容易了如:
document.forms[0].submit();
或document.getElementById("Button1").click();//如果页面中有Button1的话。
2.get方式刷新:
可以在页面上添加一个链接,模拟点击:
var
a
=
document.createElement(
"
a
"
);
a.href = document.location.href;
document.body.appendChild(a);
a.click();
a.href = document.location.href;
document.body.appendChild(a);
a.click();
或者(这个办法比较笨,但可以提供一个解决办法的思路)
在父窗口中重新打开。
如:
var
v
=
window.showModalDialog(
"
aa.aspx
"
);
while (v == " R " )
{
v = window.showModalDialog( " aa.aspx " );
}
while (v == " R " )
{
v = window.showModalDialog( " aa.aspx " );
}
在模态窗口中
window.returnValue
=
"
R
"
;
window.close();
window.close();
就可以了