HTML5 PostMessage Sample

Issues with adding a handler to onmessage for iframe

HTML

<body>
    <p>Frame1 <button id="testFrame">Test Posting</button></p>
    <br/>
    <iframe id="frame1" src="http://dl.dropbox.com/u/75275447/frame2.html" hidden="hidden"></iframe>
</body>

JavaScript

debugger;

document.getElementById("frame1").onmessage = function(e) {
    alert(e.data);
};

$("#testFrame").click(function() {
    var element = document.getElementById("frame1").contentWindow;
    
    element.onmessage = function(e) {
        alert(e.data);
    };
    
    element.postMessage("Hello from another domain", "http://dl.dropbox.com");
});