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 <title>Parent Page</title> 5 <script language="javascript" type="text/javascript"> 6 function parenttest() { 7 alert("这是父页面的方法!"); 8 } 9 function btnClick() { 10 document.getElementById("childframe").contentWindow.childtest(); 11 } 12 </script> 13 </head> 14 <body> 15 <div style="margin:auto;"> 16 <h1>This is the Parent Page.</h1> 17 <input type="button" value="调用子页面的方法" onclick="btnClick()"/> 18 </div> 19 <div style="margin:auto;"> 20 <iframe style="300px; height:300px;" id="childframe" src="ChildPage.html"></iframe> 21 </div> 22 </body> 23 </html>
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 <title>Child Page</title> 5 <script language="javascript" type="text/javascript"> 6 function childtest() { 7 alert("这是子页面的方法!"); 8 } 9 function btnClick() { 10 window.parent.parenttest(); 11 } 12 </script> 13 </head> 14 <body> 15 <div style="margin:auto;"> 16 <h1>This is the Child Page.</h1> 17 <input type="button" value="调用父页面的方法" onclick="btnClick()"/> 18 </div> 19 </body> 20 </html>