Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Test</title>
    <script>
        window.app = {
            start: function () {
                // get the iframe
                var domain = '*';
                var iframe = document.getElementById('myIFrame').contentWindow;
                // listen to custom event
                document.body.addEventListener('postMessage', function (e) {
                    console.log('postMessage has been listened');
                }, false);
                function myPostMessage(message, domain) {
                    iframe.postMessage(message, domain); //send the message and target URI
                    // creat a custom event
                    var event = new Event('postMessage');
                    document.body.dispatchEvent(event);
                }
                // send preioducally messages for example
                setInterval(function () {
                    var message = 'Time is: ' + (new Date().getTime());
                    myPostMessage(message, domain); //send the message and target URI
                }, 1000);
            }
        };
    </script>
</head>
<body onload="window.app.start();">
    <iframe id="myIFrame" src="http://www.w3schools.com"></iframe>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers