I have a script that opens up a blank popup window, then writes some content to it, like so:
var popup = window.open('', 'window_id');
popup.document.open("text/html","replace");
popup.document.writeln("some content");
popup.document.title = 'page title';
popup.document.close();
Now, in this newly opened popup window, I want to duplicate any stylesheets from the parent window. I expected this to be straightforward:
popup.document.styleSheets = window.document.styleSheets;
Unfortunately, that doesn't work because the styleSheets attribute seems to be read-only...I don't care about inline styles, just <style>
and <link ref="stylesheet">
tags, so I tried using document.getElementsByTagName()
, but can't find a cross-browser way to reliably rebuild said tags.
I've been banging my head for a few hours now and was hoping someone here could offer advice. Is there a simple way to do this?