Skip to content

Instantly share code, notes, and snippets.

@donjaime
Created March 3, 2013 22:13
Show Gist options
  • Select an option

  • Save donjaime/5078567 to your computer and use it in GitHub Desktop.

Select an option

Save donjaime/5078567 to your computer and use it in GitHub Desktop.
PostMessage into a dynamically created iframe.
var frame = document.createElement("iframe");
frame.src="https://<the mothership's domain>/inner.html";
frame.onload = function() {
// If this is a Chrome content script, contentWindow is offlimits.
frame.contentWindow.postMessage("A Message!", "https://<the mothership's domain>");
}
document.body.appendChild(frame);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment