Created
February 6, 2018 08:21
-
-
Save orzFly/aee58e317e42e327b700abb1766ada1a to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zeyihiw
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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div class='origin'></div> | |
<div class='message'></div> | |
<button onclick="fire()">Submit</button> | |
<script id="jsbin-javascript"> | |
"use strict"; | |
window.myEvent = undefined; | |
function fire() { | |
window.myEvent.postMessage({ $kawori: "submit", payload: { "a": prompt() } }, event.origin); | |
} | |
function receiveMessage(event) { | |
if (event.data && event.data.$kawori === 'init') { | |
document.querySelector('.origin').innerText = event.origin; | |
document.querySelector('.message').innerText = JSON.stringify(event.data); | |
window.myEvent = event; | |
} | |
} | |
window.addEventListener("message", receiveMessage, false); | |
if (window.parent == window) { | |
document.querySelector('.message').innerText = "唉,你直接访问这个页面是没有意义的。"; | |
} else { | |
window.parent.postMessage({ $kawori: "init" }, "*"); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">window.myEvent = undefined; | |
function fire() { | |
window.myEvent.postMessage({ $kawori: "submit", payload: { "a": prompt() } }, event.origin); | |
} | |
function receiveMessage(event) | |
{ | |
if (event.data && event.data.$kawori === 'init') { | |
document.querySelector('.origin').innerText = event.origin; | |
document.querySelector('.message').innerText = JSON.stringify(event.data); | |
window.myEvent = event; | |
} | |
} | |
window.addEventListener("message", receiveMessage, false); | |
if (window.parent == window) { | |
document.querySelector('.message').innerText = "唉,你直接访问这个页面是没有意义的。" | |
} else { | |
window.parent.postMessage({ $kawori: "init" }, "*"); | |
}</script></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
"use strict"; | |
window.myEvent = undefined; | |
function fire() { | |
window.myEvent.postMessage({ $kawori: "submit", payload: { "a": prompt() } }, event.origin); | |
} | |
function receiveMessage(event) { | |
if (event.data && event.data.$kawori === 'init') { | |
document.querySelector('.origin').innerText = event.origin; | |
document.querySelector('.message').innerText = JSON.stringify(event.data); | |
window.myEvent = event; | |
} | |
} | |
window.addEventListener("message", receiveMessage, false); | |
if (window.parent == window) { | |
document.querySelector('.message').innerText = "唉,你直接访问这个页面是没有意义的。"; | |
} else { | |
window.parent.postMessage({ $kawori: "init" }, "*"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment