Created
March 28, 2016 23:42
-
-
Save mattlundstrom/db1438ae35323e20504d to your computer and use it in GitHub Desktop.
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
// FROM http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame | |
In your main page: | |
var frame = document.getElementById('your-frame-id'); | |
frame.contentWindow.postMessage(/*any variable or object here*/, '*'); | |
In your <iframe> (contained in the main page): | |
window.addEventListener('message', function(event) { | |
// IMPORTANT: Check the origin of the data! | |
if (~event.origin.indexOf('http://yoursite.com')) { | |
// The data has been sent from your site | |
// The data sent with postMessage is stored in event.data | |
console.log(event.data); | |
} else { | |
// The data hasn't been sent from your site! | |
// Be careful! Do not use it. | |
return; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment