window.showModalDialog用法(来源网络)
父窗口代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>父窗口</title> </head> <body> <script type="text/javascript"> function onOpenWindow(){ //showModalDialog的第二个参数是传递给子窗口的值 //在子窗口可以通过window.dialogArguments方法获取 //如果不需要传递,这个参数就用window本身 var obj = document.getElementById("rtnValue").value; var result = window.showModalDialog("window.htm",obj,"dialogWidth:500px;dialogHeight:400px"); if(result != null){ var name = result[0]; document.getElementById("rtnValue").value = name; }} </script> <input name="rtnValue" type="text" id="rtnValue" value="" /> <input type="submit" name="Submit" value="打开子窗口" onclick='onOpenWindow()' /> </body> </html>
子窗口代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>子窗口</title> </head> <body> 请输入要返回的值: <input name="txtName" type="text" id="txtName" /> <input type="submit" name="Submit" value="确定" onclick='onOK();' /> <script type="text/javascript"> document.getElementById("txtName").value = window.dialogArguments; function onOK(){ var runValue=new Array; runValue[0]=document.getElementById("txtName").value; window.returnValue = runValue; window.close(); } </script> </body> </html>
浙公网安备 33010602011771号