Skip to content

Instantly share code, notes, and snippets.

@rdillmanCN
Created December 30, 2017 09:25
Show Gist options
  • Save rdillmanCN/917164f6fa860119489ad0e855b9e426 to your computer and use it in GitHub Desktop.
Save rdillmanCN/917164f6fa860119489ad0e855b9e426 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment