I am following the example given in the document :
"Open Patent Services, Cross-Domain Requests Support, Version 1.0.0"
I have upgraded the urls so they point at 3.1, also in order to prevent the error:
"Uncaught SyntaxError: Invalid target origin 'eposite' in a call to 'postMessage'. "
I changed line 18 from
client.contentWindow.postMessage(data,'eposite');
to
client.contentWindow.postMessage(data,'h:eposite');
however chrome still generates an error on the cross site file:
Refused to set unsafe header "Origin" in crosssitescript h t m l: line 37
Regards Ben
full test code here (note urls mangles to get past forum spam filter)
Code: Select all
<html>
<script language="JavaScript">
function runit() {
// Get the iframe window object
var client = document.getElementById('client');
// Create the data string to be passed to the OPS JavaScript
var data = "{'url' : 'h:eposite as per doc', " +
"'method' : 'GET', " +
"'requestHeaders' : {'Origin': 'eposite','Accept': 'application/json' }, " +
"'body' : ''" +
"}";
console.log(data);
// Use the postMessage() method in order to send the data to the
// iframe object
client.contentWindow.postMessage(data, 'h:eposite');
}
// Add event listener for your window
window.addEventListener("message", receiveMessage, false);
// Method handling window events
function receiveMessage(event) {
// Check origin of the event!
if (event.origin == "h:eposite") {
var dataJSON = eval('(' + event.data + ')');
// work with data / display data
console.log(dataJSON);
}
else {
alert("Got message from unknown source.");
}
}
</script>
<body>
<input type="button" onclick="runit()" value="runit"></input>
<iframe width=50 height=50 id="client" src="h:eposite as per doc" />
</body>
</html>