Created
May 16, 2016 07:29
-
-
Save gabskoro/1787492f4613c7735010a8cadcec237d to your computer and use it in GitHub Desktop.
Detect global JavaScript variables with iframes
This file contains hidden or 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
// http://evanhahn.com/detect-global-javascript-variables-using-iframes/ | |
(function () { | |
// Create an iframe and put it in the <body>. | |
var iframe = document.createElement('iframe') | |
document.body.appendChild(iframe) | |
// We'll use this to get a "pristine" window object. | |
var pristineWindow = iframe.contentWindow.window | |
// Go through every property on `window` and filter it out if | |
// the iframe's `window` also has it. | |
console.log(Object.keys(window).filter(function (key) { | |
return !pristineWindow.hasOwnProperty(key) | |
})) | |
// Remove the iframe. | |
document.body.removeChild(iframe) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment