Tweaked postMessage examples to use getElements rather than querySelector
This commit is contained in:
parent
60fba1166f
commit
6c237bb05f
|
@ -1,4 +1,6 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>.postMessage target</title>
|
||||
<style>
|
||||
body {
|
||||
|
@ -7,9 +9,11 @@ body {
|
|||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<strong>This iframe is located on the same domain</strong>
|
||||
<p id="test">Send me a message!</p>
|
||||
<script src="h5utils.js"></script>
|
||||
<script src="/h5utils.js"></script>
|
||||
<script>
|
||||
addEvent(window, "message", function(e){
|
||||
if ( e.origin !== "http://html5demos.com" ) {
|
||||
|
@ -18,4 +22,6 @@ addEvent(window, "message", function(e){
|
|||
document.getElementById("test").innerHTML = e.origin + " said: " + e.data;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -90,13 +90,13 @@ iframe {
|
|||
<script>
|
||||
var win = document.getElementById("iframe").contentWindow;
|
||||
|
||||
addEvent(document.querySelector('form'), 'submit', function (e) {
|
||||
addEvent(document.getElementsByTagName('form')[0], 'submit', function (e) {
|
||||
if (e.preventDefault)
|
||||
e.preventDefault();
|
||||
|
||||
win.postMessage(
|
||||
document.getElementById("message").value,
|
||||
"http://html5demos.com"
|
||||
"http://html5demos.com"
|
||||
);
|
||||
|
||||
// otherwise set the returnValue property of the original event to false (IE)
|
||||
|
|
Loading…
Reference in New Issue