Last active
January 27, 2017 09:48
-
-
Save akash1810/dda67e9c7b66c326fe2b9d41bc9fe7c0 to your computer and use it in GitHub Desktop.
Chrome wat?!
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
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body> | |
<button type="button" onclick="window.parent.postMessage({name: 'foo'}, '*');"> | |
Press Me | |
</button> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html> | |
<head></head> | |
<body> | |
<div> | |
Name = <span id="val"></span> | |
</div> | |
<iframe src="iframe.html" style="border: 0;"></iframe> | |
<script> | |
function setVal() { | |
// Firefox (correctly) thinks `event` is `undefined` | |
// Chrome, Safari, Opera think `event` is an `Object`... WAT?! | |
document.querySelector('#val').textContent = event.data.name; | |
} | |
function onMessage (event) { | |
if (event.origin !== window.location.origin) { | |
return; | |
} | |
setVal(); | |
} | |
window.addEventListener('message', onMessage, false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment