Skip to content

Instantly share code, notes, and snippets.

@rdillmanCN
Created July 27, 2017 05:30
Show Gist options
  • Save rdillmanCN/1b953513d538cf03232ed2ec450607d1 to your computer and use it in GitHub Desktop.
Save rdillmanCN/1b953513d538cf03232ed2ec450607d1 to your computer and use it in GitHub Desktop.
Check if we have access to the iframe body.
/**
* Determines if the passed iframe is a friendly iframe.
*
* @param {HTMLElement} iframe The iframe under test.
* @return {boolean} True if friendly iframe, False otherwise.
*/
function isFriendlyIframe(iframe) {
var html = null;
try {
// deal with older browsers
var doc = iframe.contentDocument || iframe.contentWindow.document;
html = doc.body.innerHTML;
} catch (err) {
// do nothing
}
return html !== null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment