在window.showModelessDialog打开的窗体中调用原窗体的alert会使IE死掉。

本文介绍了一种在IE浏览器中使用dialogArguments参数进行父窗口与子窗口间通信的方法,通过showModelessDialog和showModalDialog函数打开子窗口,并在子窗口中调用父窗口的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以dialogArguments将window作为参数传递。

test_parent_win.htm:

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" >
 3 <head>
 4     <title>无标题页</title>
 5     <script type="text/javascript">
 6     function openModelessWin()
 7     {
 8         var fs = 'dialogWidth:600px;dialogHeight:400px';
 9         var ret = window.showModelessDialog('test_child_win.htm', window, fs);
10         alert(ret); // 'here alert will make ie to death!'
11     }
12     function openModalWin()
13     {
14         var fs = 'dialogWidth:600px;dialogHeight:400px';
15         window.showModalDialog('test_child_win.htm', window, fs);
16     }
17     function doTest()
18     {
19         alert('go to hell!');
20     }
21     </script>
22 </head>
23 <body>
24 <input id="b1" type="button" value="openModelessWin" 
25     onclick="javascript:openModelessWin()" />
26 <input id="b2" type="button" value="openModalwin"
27     onclick="javascript:openModalWin()" />
28 </body>
29 </html>

test_child_win.htm:
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" >
 3 <head>
 4     <title>无标题页</title>
 5     <script type="text/javascript">
 6     function callBackTest()
 7     {
 8         if (window.dialogArguments != null)
 9         {
10             var pwin = window.dialogArguments;
11             if (pwin.doTest != null)
12             {
13                 pwin.doTest();
14             }
15         }
16     }
17     </script>
18 </head>
19 <body>
20 <input id="b1" type="button" value="CallParentWindowMethod"
21     onclick="javascript:callBackTest()" />
22 </body>
23 </html>
24 

有时会死掉。

转载于:https://www.cnblogs.com/belaliu/archive/2006/09/28/517665.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值