window.open() 传参问题:
父页面中:
url页面拿父页面的xx元素赋值
window.open() 传值问题(参考:http://www.cnblogs.com/gavindou/archive/2008/04/09/1143858.html):
a.html(父)
注意:window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no"); 中的第3个参数一定要有 modal=yes
b.html(子)
父页面中:
- window.open('url', '', 'resizable=1, menuBar=0, toolBar=0, scrollbars=yes, Status=yes, resizable=1');
url页面拿父页面的xx元素赋值
- opener.document.getElementById("xx").value="newValue";
- if(window.opener){//判断是否有父窗口,即打开本页面的窗口
- window.opener.location.reload();//刷新父窗口
- window.opener.close(); //关闭父窗口
- }
window.open() 传值问题(参考:http://www.cnblogs.com/gavindou/archive/2008/04/09/1143858.html):
a.html(父)
注意:window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no"); 中的第3个参数一定要有 modal=yes
- <!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>a.html文档</title>
- <script type="text/javascript">
- function openstr()
- {
- window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no");
- }
- </script>
- </head>
- <body>
- <form id="form1" name="form1" method="post" action="">
- <label>
- <select name="txtselect" id="txtselect">
- </select>
- </label>
- <label>
- <input type="button" name="Submit" value="打开子窗口" οnclick="openstr()" />
- </label>
- </form>
- </body>
- </html>
b.html(子)
- <html >
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>b.html文档</title>
- <script type="text/javascript">
- function ClickOk()
- {
- var t=document.Edit;
- var color=t.color.value;
- if(color==null||color=="填写颜色") return(false);
- var oOption = window.opener.document.createElement('OPTION');
- oOption.text=document.getElementById("color").value;
- oOption.value=document.getElementById("color").value;
- //检查浏览器类型
- var bname = navigator.appName;
- if (bname.search(/netscape/i) == 0)
- {
- window.opener.document.getElementById("txtselect").appendChild(oOption);
- }
- else if (bname.search(/microsoft/i) == 0)
- {
- window.opener.document.all.txtselect.add(oOption);
- }
- else
- {
- }
- window.close();
- }
- </script>
- </head>
- <body>
- <table border="0" cellpadding="0" cellspacing="2" align="center" width="300">
- <form name="Edit" id="Edit">
- <tr>
- <td width="30" align="right" height="30">color:</td>
- <td height="30"><input type="text" name="color" id="color" value="填写颜色" /></td>
- <td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" οnclick="ClickOk();" /> </td>
- </tr>
- </form>
- </table>
- </body>
- </html>
- var url = '/xxx/xx.jsp?yearNum='+yearNum;
- if (typeof window.ActiveXObject != 'undefined') { // 支持IE浏览器
- var weekNum=document.getElementById("weekNum").value;
- var arguments = new Array();
- arguments[0] = weekNum;
- var returnValue = window.showModalDialog(url,arguments,'dialogHeight:500px;dialogWidth:380px;dialogTop:300px; dialogLeft:500px;center:yes;scroll:yes;status:no;resizable:no;edge:raised;help:no;unadorned:yes');
- if(returnValue!=null && returnValue[0]){
- document.getElementById("weekNum").value=returnValue[1];
- document.getElementById("beginDate").value=returnValue[2];
- document.getElementById("endDate").value=returnValue[3];
- }
- }
- else if((typeof document.implementation != 'undefined')
- &&(typeof document.implementation.createDocument!='undefined')) { // 支持Mozilla浏览器
- window.open(url,'weekNum','modal=yes,menubar=0,status=0,toolbar=0,scrollbars=1,resizable=1,width=400px,height=500px,top=300,left=500');
- }