Created
September 24, 2013 18:59
-
-
Save geraintluff/6689572 to your computer and use it in GitHub Desktop.
Duplicates <link> and <style> elements in a new document (useful for spawning sub-windows)
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 copyStyle(oldDoc, newDoc) { | |
var links = oldDoc.getElementsByTagName('link'); | |
for (var i = 0; i < links.length; i++) { | |
var oldElement = links[i]; | |
var newElement = newDoc.createElement('link'); | |
newElement.rel = oldElement.rel; | |
newElement.href = oldElement.href; | |
newDoc.head.appendChild(newElement); | |
} | |
var styles = oldDoc.getElementsByTagName('style'); | |
for (var i = 0; i < styles.length; i++) { | |
var oldElement = styles[i]; | |
var newElement = newDoc.createElement('style'); | |
newElement.innerHTML = oldElement.innerHTML; | |
newDoc.head.appendChild(newElement); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment