javascript - Either postMessage or addEventListener not working -
the following javascript code uses html5 postmessage / addeventlistener functions send message itself:
window.addeventlistener('testmsg', function(event) { alert('got message'); /* never happens. why? */ }, false ); window.addeventlistener('load', function(event) { alert('sending message'); window.postmessage('testmsg', '*'); }, false);
a corresponding fiddle:
the message never received. reason?
i have modified fiddle. listening wrong event.
should be
window.addeventlistener('message', function(event) { alert('got message'); /* never happens. why? */ }, false ); window.addeventlistener('load', function(event) { alert('sending message'); window.postmessage('message', '*'); }, false);
Comments
Post a Comment