Created
October 31, 2019 03:08
-
-
Save nirkaufman/9638b67de73f61a3ea3f33f7d6b1587a to your computer and use it in GitHub Desktop.
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
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); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you