Skip to content

Instantly share code, notes, and snippets.

@champierre
Created September 27, 2012 08:40
Show Gist options
  • Select an option

  • Save champierre/3792928 to your computer and use it in GitHub Desktop.

Select an option

Save champierre/3792928 to your computer and use it in GitHub Desktop.
Reload the contents of iframe on Windows Metro Style App
== 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