A页面触发B页面事件

来源:互联网 发布:java中非线程安全的类 编辑:程序博客网 时间:2024/05/23 01:07

a.html

[html] view plaincopyprint?
  1. <html>  
  2. <body>  
  3. 要传的值  
  4. <input type='text' id='txtID' name='txtName' value='avalue' /> <br>  
  5. <input type='button' value='open' onclick="window.open('b.html');" />  
  6.   
  7. <script>  
  8. alert('刷新了页面');  
  9. function method()  
  10. {  
  11.     alert('a.html');  
  12. }  
  13. </script>  
  14. </body>  
  15. </html>  

b.html
[html] view plaincopyprint?
  1. html>  
  2. <script>  
  3. function getValue()  
  4. {  
  5.         document.getElementById('txt').value=window.opener.document.getElementById('txtID').value;  
  6. }  
  7. </script>  
  8. <body onload='getValue();'>  
  9. 传过来的值是  
  10. <input type='text' id='txt' />  
  11. <input type='button' value='调用父窗口的方法' onclick='window.opener.method();' />  
  12. <br>  
  13. <br>  
  14. <br>  
  15. 设置父窗口的文本<input type='text' id='t' />  
  16. <input type='button' value='执行'   
  17. onclick='window.opener.document.getElementById("txtID").value=document.getElementById("t").value;' />  
  18. <br>  
  19. <br>  
  20. <input type='button' value='刷新父窗口' onclick='window.opener.location=window.opener.location;' />  
  21. <br>  
  22. <br>  
  23. <input type='button' value='关闭父窗口' onclick='window.opener.close();opener=null;' />  
  24. </body>  
  25. </html>  



父子页面事件

a.html

[html] view plaincopyprint?
  1. <input type='button' value='showModalDialog' onclick="window.showModalDialog('c.html',window);" />  

c.html
[html] view plaincopyprint?
  1. <html>  
  2. <script>  
  3. function getValue()  
  4. {  
  5.     if(window.dialogArguments)  
  6.         {  
  7.           document.getElementById('txt').value=window.dialogArguments.document.getElementById('txtID').value;       
  8.         }  
  9.           
  10. }  
  11. </script>  
  12. <body onload='getValue();'>  
  13. 传过来的值是  
  14. <input type='text' id='txt' />  
  15. <input type='button' value='调用父窗口的方法' onclick='window.dialogArguments.method();' />  
  16. <br>  
  17. <br>  
  18. <br>  
  19. 设置父窗口的文本<input type='text' id='t' />  
  20. <input type='button' value='执行'   
  21. onclick='window.dialogArguments.document.getElementById("txtID").value=document.getElementById("t").value;' />  
  22. <br>  
  23. <br>  
  24. <input type='button' value='刷新父窗口' onclick='window.dialogArguments.location=window.dialogArguments.location;' />  
  25. <br>  
  26. <br>  
  27. <input type='button' value='关闭父窗口' onclick='window.dialogArguments.close();' />  
  28. </body>  
  29. </html>  



0 0