码迷,mamicode.com
首页 > Windows程序 > 详细

window.postmessage

时间:2019-07-05 15:34:37      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:get   width   charset   htm   mes   frame   com   false   idt   

<html>
    <head>
        <title>test</title>
        <style>
            iframe{
                border: 1px solid red;
            }
        </style>
    </head>
    <body>
        <iframe src="./content.html" frameborder="0" id=‘receiver‘></iframe>
        <script>
            window.onload = () => {
                var  receiverWindow = document.getElementById(‘receiver‘).contentWindow;
                receiverWindow.postMessage(‘hello‘,‘*‘)
            }
        </script>
    </body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p>postmessage</p>
    <script>
        window.addEventListener(‘message‘,function(e){
            console.log(‘message is ok‘,e.data);
        },false)
    </script>
</body>
</html>

 

window.postmessage

标签:get   width   charset   htm   mes   frame   com   false   idt   

原文地址:https://www.cnblogs.com/l8l8/p/11138554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!