Created
July 27, 2017 05:30
-
-
Save rdillmanCN/1b953513d538cf03232ed2ec450607d1 to your computer and use it in GitHub Desktop.
Check if we have access to the iframe body.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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