window.open() 父子页面的传参&传值问题

来源:互联网 发布:重复歌曲删除软件 编辑:程序博客网 时间:2024/06/05 19:43
window.open() 传参问题: 
父页面中: 
Java代码  收藏代码
  1. window.open('url''''resizable=1, menuBar=0, toolBar=0, scrollbars=yes, Status=yes, resizable=1');  


url页面拿父页面的xx元素赋值 
Java代码  收藏代码
  1. opener.document.getElementById("xx").value="newValue";  


Java代码  收藏代码
  1. if(window.opener){//判断是否有父窗口,即打开本页面的窗口  
  2.     window.opener.location.reload();//刷新父窗口  
  3.     window.opener.close();  //关闭父窗口  
  4. }  



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 
Java代码  收藏代码
  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. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />   
  5. <title>a.html文档</title>   
  6. <script type="text/javascript">   
  7. function openstr()   
  8. {   
  9. window.open("b.html","","modal=yes,width=500,height=500,resizable=no,scrollbars=no");   
  10. }  
  11.   
  12. </script>   
  13. </head>   
  14.   
  15. <body>   
  16. <form id="form1" name="form1" method="post" action="">   
  17. <label>   
  18. <select name="txtselect" id="txtselect">   
  19. </select>   
  20. </label>   
  21. <label>   
  22. <input type="button" name="Submit" value="打开子窗口" onclick="openstr()" />   
  23. </label>   
  24. </form>   
  25. </body>   
  26. </html>   


b.html(子) 
Java代码  收藏代码
  1. <html >   
  2. <head>   
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />   
  4. <title>b.html文档</title>   
  5. <script type="text/javascript">   
  6. function ClickOk()   
  7. {   
  8. var t=document.Edit;   
  9. var color=t.color.value;   
  10. if(color==null||color=="填写颜色"return(false);   
  11. var oOption = window.opener.document.createElement('OPTION');   
  12. oOption.text=document.getElementById("color").value;   
  13. oOption.value=document.getElementById("color").value;   
  14. //检查浏览器类型  
  15. var bname = navigator.appName;  
  16. if (bname.search(/netscape/i) == 0)  
  17. {  
  18. window.opener.document.getElementById("txtselect").appendChild(oOption);   
  19. }  
  20. else if (bname.search(/microsoft/i) == 0)  
  21. {  
  22. window.opener.document.all.txtselect.add(oOption);   
  23. }  
  24. else  
  25. {  
  26. }  
  27. window.close();   
  28. }   
  29. </script>   
  30. </head>   
  31. <body>   
  32. <table border="0" cellpadding="0" cellspacing="2" align="center" width="300">   
  33. <form name="Edit" id="Edit">   
  34. <tr>   
  35. <td width="30" align="right" height="30">color:</td>   
  36. <td height="30"><input type="text" name="color" id="color" value="填写颜色" /></td>   
  37. <td width="56" align="center" height="30"><input " type="button" name="bntOk" value="确认" onclick="ClickOk();" /> </td>   
  38. </tr>   
  39. </form>   
  40. </table>   
  41. </body>   
  42. </html>  



Java代码  收藏代码
  1. var url = '/xxx/xx.jsp?yearNum='+yearNum;  
  2.           
  3.         if (typeof window.ActiveXObject != 'undefined') { // 支持IE浏览器  
  4.             var weekNum=document.getElementById("weekNum").value;  
  5.             var arguments    = new Array();  
  6.             arguments[0] = weekNum;  
  7.             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');  
  8.             if(returnValue!=null && returnValue[0]){  
  9.                 document.getElementById("weekNum").value=returnValue[1];  
  10.                 document.getElementById("beginDate").value=returnValue[2];  
  11.                 document.getElementById("endDate").value=returnValue[3];  
  12.             }   
  13.         }  
  14.         else if((typeof document.implementation != 'undefined')  
  15.                     &&(typeof document.implementation.createDocument!='undefined')) { // 支持Mozilla浏览器  
  16.   
  17.             window.open(url,'weekNum','modal=yes,menubar=0,status=0,toolbar=0,scrollbars=1,resizable=1,width=400px,height=500px,top=300,left=500');  
  18.           
  19.         }  
0 0