vReturnValue = window.showModalDialog(sURL [, vArguments] [,sFeatures])
sFeatures 可选参数有:
具体使用如下:
主页:index.html
<html> <head> <title> 弹出框小例子 </title> <script> function showWinPassArr(){ var arr=['test1','19','famle'];//构造参数-数组传递给子窗口 var str =showModalDialog('children.html',arr,'dialogWidth=280px;dialogHeight=200px;title=测试弹出框');//定义变量str接收返回值。 alert(str[0]+str[1]);//弹出返回值 } function showWinPassObj(){ var obj={name:'test1',age:19,sex:'famle'};//构造参数-对象传递给子窗口 showModalDialog('children2.html',obj,'dialogWidth=280px;dialogHeight=200px'); } function showOpenWin(){ window.open("http://www.kao.com/","Window Name", "menubar=no,location=no,resizable=no,scrollbars=no,status=no"); } </script> </head> <body> <input type="button" value="弹出模态窗口-传递数组参数" onclick="showWinPassArr();"/> <input type="button" value="弹出模态窗口-传递对象参数" onclick="showWinPassObj();"/> <input type="button" value="winOpen" onclick="showOpenWin();"/> </body> </html>
弹出框子页面children.html
<html> <head> <title>接收传递参数为数组</title> </head> <script> var arr = window.dialogArguments;//接收参数 alert("name:"+arr[0]+" age:"+arr[1]+" sex:"+arr[2]); var rtnarr=['这个是从子窗口返回的参数','1234567'];//构造返参 window.returnValue=rtnarr;//回传参数 </script> <body> <center> children.html</center> </body> </html>
弹出框子页面children2.html
<html> <head> <title>接收传递参数为对象</title> </head> <script> var obj = window.dialogArguments; alert(obj.age); </script> <body> children2.html </body> </html>