Created
November 12, 2014 13:00
-
-
Save shaunwallace/16418f9b255d448d9b34 to your computer and use it in GitHub Desktop.
Scripting inside HTML imports
This file contains hidden or 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
// the scripts inside of the import reference it's containing document | |
var import = document.currentScript.ownerDocument; | |
// the main document references itself | |
var doc = document; | |
// now we can grab things we need from the imported document and clone them into the main document | |
// here we are grabbing the styles from the imported document and adding them to the main page | |
var styles = import.querySelector('link[rel="stylesheet"]'); | |
doc.head.appendChild(styles.cloneNode(true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment