Created
September 27, 2012 08:40
-
-
Save champierre/3792928 to your computer and use it in GitHub Desktop.
Reload the contents of iframe on Windows Metro Style App
This file contains hidden or 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
| == in the page in iframe | |
| <script type="text/javascript"> | |
| window.attachEvent("onmessage", receiveMessage); | |
| function receiveMessage(e) { | |
| if (e.data == "refresh") { | |
| history.go(0); | |
| } | |
| } | |
| </script> | |
| == default.html == | |
| <iframe id="iframe" src="http://example.com" width="800px" height="400px"></iframe> | |
| <button id="reloadButton">Reload</button> | |
| == default.js == | |
| var reloadButton = document.getElementById("reloadButton"); | |
| reloadButton.addEventListener("click", reload, false); | |
| function reload() { | |
| var iframe = document.getElementById("iframe"); | |
| iframe.contentWindow.postMessage("refresh", *); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment