showModalDialog打开showModalDialog设置_self无效

很多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

<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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值