Skip to content

Instantly share code, notes, and snippets.

@gabskoro
Created May 16, 2016 07:29
Show Gist options
  • Save gabskoro/1787492f4613c7735010a8cadcec237d to your computer and use it in GitHub Desktop.
Save gabskoro/1787492f4613c7735010a8cadcec237d to your computer and use it in GitHub Desktop.
Detect global JavaScript variables with iframes
// 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