Skip to content

Instantly share code, notes, and snippets.

@papucho
Created October 4, 2013 09:33
Show Gist options
  • Save papucho/6823394 to your computer and use it in GitHub Desktop.
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.
<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