Skip to content

Instantly share code, notes, and snippets.

@HomerJSimpson
Last active August 29, 2015 14:20
Show Gist options
  • Save HomerJSimpson/7538899c43a572a558f3 to your computer and use it in GitHub Desktop.
Save HomerJSimpson/7538899c43a572a558f3 to your computer and use it in GitHub Desktop.
walk iframes
var myFrames = [];
function mkLog(name) {
return function() {
console.log('unloading ' + name);
};
}
(function walk(d) {
var doc = d.contentDocument || d, i, iframes = doc.getElementsByTagName('iframe');
console.log('found ' + iframes.length + ' iframes');
myFrames.push({ doc :doc, frame : d.contentDocument, node : d, id : d.id, name:d.name });
if(d.tagName === "IFRAME") {
d.contentWindow.onbeforeunload = mkLog(d.id);
}
for(i=0;i<iframes.length;++i) {
try {
walk(iframes[i]);
} catch(e) { console.log('skipping'); }
}
}(document));console.dir(myFrames);"done";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment