<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
<head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head>
<body> <script type="text/javascript"> function hello(x) { alert(x) } var aaaa='父级变量'; function child(){ alert(a.window.bbbb); } </script> <button id="maindiv" οnclick="child()">子级变量</button> <iframe id="a" name="a" src="b.html" width="600" height="400"></iframe> </body>
</html>
<!--b.html 谷歌浏览器需在同一个域名下-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html>
<head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head>
<body> <script type="text/javascript"> var bbbb = "子级变量"; function callParent(x) { alert(window.parent.aaaa); window.parent.hello(x); } </script> <button οnclick="callParent(this.innerHTML)">父级方法/变量</button> </body>
</html>