首页 > 代码库 > node-webkit 主页面和 iframe 页通讯

node-webkit 主页面和 iframe 页通讯

<html lang="en-US">
<head>
<title>Hello World!</title>
<style>
</style>
</head>
<body>
<iframe src=http://www.mamicode.com/"http://rwdev.meilishuo.com/test/im" id="f"></iframe>
<script >
var win = document.getElementById(f).contentWindow

var fs = require(fs)

win.onload = function(){
    var t = fs.statSync(./)
    win.postMessage(t,win.location.href)
}
win.addEventListener(message, function(event){
    console.log(parent receive : ,event.data)

    }, false)
</script>
</body>
</html>

 

 

<html lang="en-US">
<head>
</head>
<body>
 
<script >
window.postMessage(t,window.location)
window.addEventListener("message", function(event){
    console.log(child receive ,event.data)
    document.body.innerHTML += <pre>+ JSON.stringify(event.data) + </pre>
    }, false);
</script>
</body>
</html>