Last active
December 16, 2015 03:29
-
-
Save sangar82/5370300 to your computer and use it in GitHub Desktop.
window.postMessage is a method for safely enabling cross-origin communication. Normally, scripts on different pages are only allowed to access each other if and only if the pages which executed them are at locations with the same protocol (usually both http), port number (80 being the default for http), and host (modulo document.domain being set…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Domain A with iframe: | |
----------------------- | |
<iframe></iframe> | |
<script> | |
window.addEventListener( "message", | |
function (e) { | |
if(e.origin !== 'http://www.domainB.com'){ return; } | |
alert(e.data); | |
}, | |
false); | |
</script> | |
Domain B, content for the iframe | |
----------------------- | |
$(window).load() { | |
top.postMessage("message", '*'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment