Skip to content

Instantly share code, notes, and snippets.

@nirkaufman
Created October 31, 2019 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nirkaufman/9638b67de73f61a3ea3f33f7d6b1587a to your computer and use it in GitHub Desktop.
Save nirkaufman/9638b67de73f61a3ea3f33f7d6b1587a to your computer and use it in GitHub Desktop.
function copyStyles(sourceDoc, targetDoc) {
Array.from(sourceDoc.styleSheets).forEach(styleSheet => {
if (styleSheet.cssRules) {
const newStyleEl = sourceDoc.createElement('style');
Array.from(styleSheet.cssRules).forEach(cssRule => {
newStyleEl.appendChild(sourceDoc.createTextNode(cssRule.cssText));
});
targetDoc.head.appendChild(newStyleEl);
} else if (styleSheet.href) {
const newLinkEl = sourceDoc.createElement('link');
newLinkEl.rel = 'stylesheet';
newLinkEl.href = styleSheet.href;
targetDoc.head.appendChild(newLinkEl);
}
});
}
@heecheolman
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment