Skip to content

Instantly share code, notes, and snippets.

@geraintluff
Created September 24, 2013 18:59
Show Gist options
  • Save geraintluff/6689572 to your computer and use it in GitHub Desktop.
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)
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