您的位置:首页 > 其它

关闭模态子窗口的同时刷新父窗口的问题

2012-11-14 21:57 274 查看
主要实现的功能是当点击模态子窗口的右上角的红X时,实现刷新父窗口的功能

原本是想在子窗口中直接这样写: body onunload="refresh()"

function refresh() {
window.close();window.opener.location.href = window.opener.location.href;
}

window.onunload = refresh;
但是这样写就在IE8下报错,指向这一行 body onunload="refresh()" 不支持该属性或方法 然后又看了这个链接

http://www.w3help.org/zh-cn/causes/SD9026 发现各个浏览器下对onunload事件的支持有差异,所以就没用这个方法

在网上找了一阵资料后 采用了别的方法,直接在父窗体写代码来实现,代码如下

<script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript">
$(function () {
$("#test").click(function () {
var str = window.showModalDialog("Dialog.aspx", "dialogWidth=200px;dialogHeight=100px");
if (str == undefined) {
window.location.href = window.location.href;
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button"  value="单击弹出模态窗口" id="test" />
</div>
</form>
</body>


通过给window.showModalDialog的返回值进行判断,当子窗口关闭时返回值就变为undefined,同时刷新父窗口
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: