HTML5 PostMessage Library Sample v2
Posting Messages Cross-Domain because security policies are dumb. Version 2
by shelbyz
HTML
<body>
<button id="post">Post</button>
<br/>
<button id="get">Get</button>
<br/>
<label id="final">Results: </label>
<iframe id="frame1" src="http://dl.dropbox.com/u/75275447/libFrame.html" hidden="hidden"></iframe>
</body>
JavaScript
//debugger;
window.onmessage = function(e) {
if ( e.origin !== "http://dl.dropbox.com" ) {
alert("Message originated from: " + e.origin);
return;
}
$("#final").text("Results: " + e.data);
//alert(e.data);
};
function postCallback() {
alert("I'm the post callback");
}
function getCallback() {
alert("I'm the get callback");
}
$("#post").click(function() {
var data = {
verb: "post",
url: "http://www.sample.com/",
data: "This is some data",
successFunc: postCallback,
contentType: "application/json"
};
document.getElementById("frame1").contentWindow.postMessage(JSON.stringify(data), "http://dl.dropbox.com");
});
$("#get").click(function() {
var data = {
verb: "get",
targetPath: "/samples",
successFunc: getCallback,
acceptType: "application/json"
};
document.getElementById("frame1").contentWindow.postMessage(JSON.stringify(data), "http://dl.dropbox.com");
});