Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created May 30, 2010 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miya2000/419354 to your computer and use it in GitHub Desktop.
Save miya2000/419354 to your computer and use it in GitHub Desktop.
javascript:(function(){
var ifr = document.createElement('iframe');
ifr.src = 'data:text/html;charset=utf-8,%3Chtml%3E%0D%0A%3Cbody%3E%0D%0A%3Cscript%20type%3D%22text%2Fjavascript%22%3E%0D%0Awindow.addEventListener(%22message%22%2C%20receiveMessage%2C%20false)%3B%0D%0Afunction%20receiveMessage(e)%20%7B%0D%0A%20%20%20%20alert(localStorage%5B%22aaa%22%5D)%3B%0D%0A%20%20%20%20localStorage%5B%22aaa%22%5D%20%3D%20e.data%3B%0D%0A%20%20%20%20alert(localStorage%5B%22aaa%22%5D)%3B%0D%0A%7D%0D%0A%3C%2Fscript%3E%0D%0A%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E%0D%0A';
document.body.appendChild(ifr);
ifr.addEventListener('load', function() {
alert('post');
ifr.contentWindow.postMessage('aaaaaaaaaa', '*');
}, false);
})()
<html>
<body>
<script type="text/javascript">
window.addEventListener("message", receiveMessage, false);
function receiveMessage(e) {
alert(localStorage["aaa"]);
localStorage["aaa"] = e.data;
alert(localStorage["aaa"]);
}
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment