Created
December 30, 2017 09:25
-
-
Save rdillmanCN/917164f6fa860119489ad0e855b9e426 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment