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

以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 

有时会死掉。

posted on 2006-09-28 22:36  bela liu  阅读(547)  评论(0编辑  收藏  举报

导航