模式窗体中调用父页面Javascript

本文介绍了模式窗体与非模式窗体的区别,并通过示例展示了如何利用JavaScript实现子窗体与父窗体之间的数据传递及刷新。

最近项目中使用模式窗体,遇到以下问题记录一下:

模式窗体:你必须关闭该窗体,才能操作其它窗体;比如说,必须按确定或取消,或者按关闭。

非模式窗体:不必关闭该窗体,就可转换到其它窗体上进行操作。

window.showModalDialog("a.html");//模式窗体

弹出的子页面,无法调用父页面里的js,从而刷新父页面,google一下,发现了解决方案:

  1. parent.html
<html>
<head>
<script language="text/javascript">
function openwindow(){
    retval=window.showModalDialog("child.html")
    Alert(retval);
    document.getElementById('text1').value=retval
}

function Alert(msg){
    alert(msg);
}
</script>
</head>
<body>
<form name=frm>
<input name=text1 type=text id="text1"/>
<input type=button onclick="javascript:openwindow()" value="Open window..">
</form>
</body>
</html>

2. child.html

<html>
<head>
<script language="javascript">
function changeparent(){
    window.returnValue="Value changed.."
    window.close()
}
</script>
</head>
<body>
<form>
<input type=button onclick="javascript:changeparent()" value="Change main window’s textbox value..">
</form>
</body>
</html>

 

转载于:https://www.cnblogs.com/wspaceworld/p/3836821.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值