I'm attempting to write a greasemonkey script that brings up a
messaging window in an iframe that is on a different domain. To send
the information to that iframe from the parent window, I'm trying to
use the postMessage() function, but for some reason I can't get it to
send and/or receive to and from the iframe.
In the greasemonkey script I create a new iframe (I'm using jquery):
$('body').append('<iframe src="
http://mysite.com/api.php" id="com"></
iframe>');
In the api.php, I have:
window.addEventListener('message', function(e){
document.getElementById('test').textContent = e.domain+' said:
'+e.data;
}, false);
Now, further down in the greasemonkey script I try and send a simple
message:
window.parent.frames[0].postMessage('hello world', 'http://
mysite.com');
It doesn't register and it doesn't throw any errors to let me know why
it isn't sending. I type the above javascript into FireBug and it
displays perfectly in the iframe and registers that it was sent. Why
doesn't this work the same in Greasemonkey? Is there a work-around or
am I calling the window improperly from the chrome or where ever
greasemonkey is relative to the iframe?
I'm really at a loss to exactly why it won't work. Any help would be
appreciated!
Thanks,
slickplaid