Skip to content

Instantly share code, notes, and snippets.

@bjensen
Created July 13, 2009 18:11
Show Gist options
  • Save bjensen/146346 to your computer and use it in GitHub Desktop.
Save bjensen/146346 to your computer and use it in GitHub Desktop.
Get the iframe document object
/ How to get the iframe document object
// Assume 'iframe' is a variable to the iframe DOM element
var iframe_document = null;
if (iframe.contentDocument) iframe_document = iframe.contentDocument;
else if (iframe.contentWindow) iframe_document = iframe.contentWindow.document;
else if (iframe.document) iframe_document = iframe.document;
else throw(new Error("Cannot access iframe document."));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment