很多TX在开发过程中会用到showModalDialog,今天我说下自己在开发过程中碰到的问题:
1、如果直接通过showModalDialog弹出窗体,如果关闭子窗口需要刷新父窗口,在子窗体head里面加上<base target="_self"/>
<meta http-equiv="pragma" content="no-cache">,target="_self" 指明不开新的窗口,相对的_blank,是在新窗口打开文件。
2、如果父窗体是showModalDialog窗体,在在父窗体打开showModalDialog窗体,如果关闭子窗体时要需要刷新父窗体,需要关闭父窗体重新打开。参照下面的例子。
a.html打开showModalDialog窗体b.html,在b.html代开showModalDialog窗体c.html
关闭c.html刷新b.html,此时单单使用第一种方法就无法达到预期效果(但是<base target="_self"/>还是要加在head里面),此时就需要关闭b.html,让a.html再次打开b.html.
代码如下:
a.html
b.html
c.html
参照:http://www.iteye.com/problems/37060
1、如果直接通过showModalDialog弹出窗体,如果关闭子窗口需要刷新父窗口,在子窗体head里面加上<base target="_self"/>
<meta http-equiv="pragma" content="no-cache">,target="_self" 指明不开新的窗口,相对的_blank,是在新窗口打开文件。
2、如果父窗体是showModalDialog窗体,在在父窗体打开showModalDialog窗体,如果关闭子窗体时要需要刷新父窗体,需要关闭父窗体重新打开。参照下面的例子。
a.html打开showModalDialog窗体b.html,在b.html代开showModalDialog窗体c.html
关闭c.html刷新b.html,此时单单使用第一种方法就无法达到预期效果(但是<base target="_self"/>还是要加在head里面),此时就需要关闭b.html,让a.html再次打开b.html.
代码如下:
a.html
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
</head>
<script type="text/javascript">
function test(){
var ret = window.showModalDialog("b.html", window,
'dialogWidth:500px;dialogHeight:520px;status:no;help:no');
if(ret == 1){
window.location.reload();
}
}
</script>
<body>
<input type="button" onclick="test();" value="button"/>
</body>
</html>
b.html
<html>
<head>
<base target="_self"/>
<meta http-equiv="pragma" content="no-cache">
</head>
<script type="text/javascript">
function closes() {
window.returnValue=1;
window.close();
}
function test(){
var ret = window.showModalDialog("c.html", 'checkout',
'dialogWidth:500px;dialogHeight:520px;status:no;help:no');
if(ret == 1){
window.location.replace("b.html");
//window.location.reload();
}
}
</script>
</script>
<body>
bbbbbbbbbbbbbbbbbbbbbb
<input type="button" onclick="test();" value="button"/>
<input type="button" onclick="closes();" value="close"/>
<script>
alert("加载B.html页面");
</script>
</body>
</html>
c.html
<html>
<head>
<base target="_self"/>
<meta http-equiv="pragma" content="no-cache">
</head>
<script type="text/javascript">
function test() {
window.returnValue=1;
window.close();
}
</script>
<body>
cccccccccccccccc
<input type="button" onclick="test();" value="close"/>
</body>
</html>
参照:http://www.iteye.com/problems/37060