index.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>页面一</title>
</head>
<body>
<button οnclick="sendPage2();" type="button">send page2</button>
<hr>
<iframe src="http://192.168.3.24/jyn/admins/wx/add_material" name="iframe" frameborder="0" scrolling="no"></iframe>
</body>
<script>
function sendPage2(){
window.frames.iframe.postMessage("this is page one","*");
}
window.addEventListener("message", function( e ) {
console.log(e.data);
}, false );
</script>
</html>
index2.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>页面二</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 400px;
height: 200px;
background: #4E98DD
}
</style>
</head>
<body>
<div class="box">
this is node page
<button id="btn" οnclick="sendParent()" type="button">send parent</button>
</div>
<script>
window.addEventListener("message", function( e ) {
console.log(e.data);
}, false );
function sendParent(){
window.parent.postMessage("this pages2","*")
}
</script>
</body>
</html>