Skip to content

Instantly share code, notes, and snippets.

@victorjonsson
Created August 19, 2015 12:28
Show Gist options
  • Save victorjonsson/921096ff09fefb6e3000 to your computer and use it in GitHub Desktop.
Save victorjonsson/921096ff09fefb6e3000 to your computer and use it in GitHub Desktop.
window.addEventListener("load", function() {
var self = window.self,
parent = window.parent,
setTransparentBackground = function(doc) {
doc.getElementsByTagName('html')[0].style.background = 'transparent';
doc.getElementsByTagName('body')[0].style.background = 'transparent';
};
// make current doc transparent
setTransparentBackground(window.document);
// Iterate upwards over all iframes frome here
while(self != parent) {
var parentIframes = parent.document.getElementsByTagName('iframe'),
iframe = false,
iframeDoc = false;
// Find iframe holding this document in parent window
for(var i=0; i < parentIframes.length; i++) {
iframeDoc = parentIframes[i].contentDocument || parentIframes[i].contentWindow.document;
if( iframeDoc === self.document ) {
iframe = parentIframes[i];
break;
}
}
if( iframe ) {
setTransparentBackground(iframeDoc);
iframe.allowTransparency = 'true';
self = parent;
parent = self.parent;
} else {
break;
}
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment