Created
October 4, 2013 09:33
-
-
Save papucho/6823394 to your computer and use it in GitHub Desktop.
Simple Javascript to allow an iframe to have it's parent css rules.
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
<script> | |
var parentStyleSheets = this.parent.document.styleSheets; | |
var cssString = []; | |
for (var i = 0, count = parentStyleSheets.length; i < count; i++) | |
{ | |
var cssRules = parentStyleSheets[i].cssRules; | |
if(cssRules) | |
for (var j = 0, countJ = cssRules.length; j < countJ; j++) | |
cssString.push(cssRules[j].cssText); | |
} | |
var styleEl = document.createElement('style'); | |
styleEl.type = 'text/css'; | |
styleEl.innerHTML = cssString.join("\n"); | |
document.head.appendChild(styleEl); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment