html5demos/postmessage2.html

116 lines
2.3 KiB
HTML

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>HTML5 Demo: postMessage (cross domain)</title>
<style>
body {
font: normal 16px/20px Helvetica, sans-serif;
background: rgb(237, 237, 236);
margin: 0;
margin-top: 40px;
padding: 0;
}
input {
font: normal 16px/20px Helvetica, sans-serif;
}
section, header, footer {
display: block;
}
#wrapper {
width: 600px;
margin: 0 auto;
background: #fff url(images/shade.jpg) repeat-x center bottom;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
border-top: 1px solid #fff;
padding-bottom: 76px;
}
h1 {
padding-top: 10px;
}
h2 {
font-size: 100%;
font-style: italic;
}
header,
article > *,
footer > * {
margin: 20px;
}
footer > * {
margin: 20px;
color: #999;
}
#status {
padding: 5px;
color: #fff;
background: #ccc;
}
#status.offline {
background: #c00;
}
#status.online {
background: #0c0;
}
iframe {
width: 100%;
border: 2px solid #ccc;
}
</style>
<script src="h5utils.js"></script>
</head>
<body>
<section id="wrapper">
<header>
<h1>Cross Domain postMessage</h1>
</header>
<article>
<form>
<p><label for="message">Message</label><input type="text" name="message" value="my message" id="message" /> <input type="submit" />
</p>
<h2>Target iframe:</h2>
<iframe id="iframe" src="http://jsbin.com/uderi"></iframe>
</form>
</article>
<footer><a href="/">HTML5 demo</a></footer>
</section>
<script>
var win = document.getElementById("iframe").contentWindow;
addEvent(document.querySelector('form'), 'submit', function (e) {
win.postMessage(
document.getElementById("message").value,
"http://jsbin.com"
);
if (e.preventDefault)
e.preventDefault();
// otherwise set the returnValue property of the original event to false (IE)
e.returnValue = false;
});
</script>
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script>
try {
var pageTracker = _gat._getTracker("UA-1656750-18");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>