What is Same Origin Policy (SOP)
Same Origin Policy Examples
Why same origin policy in the first place
What is the downside of SOP.
?Issues of SOP dealt with in HTML5
?What is & Why Cross-Domain Messaging
Posting a Message to another iframe (from Host window)
<body> <p> The source origin of this page is http://abc.domain1.com</p> <script> aframe = document.getElementById('iframe'); aframe.postMessage("Hello World", //Message to post "http://def.domain2.com" //Target Origin ) </script> <p> Target iframe </p> <iframe id="iframe" src ="http://def.domain2.com/my_iframe.html"></iframe> </body>
Receiving a Message from the iframe (in host window)
<script> //Handle message received from the iframe window.addEventListener('message',function(e){ if(e.origin !== "http://def.domain2.com") { //filter origin for security reasons //Disregard the message since it is not from a valid origin } else{ //e.data contains message from the sender } }, false); </script>
Thanks for reading!