简体   繁体   中英

How to get the stylesheets from a manually created document?

If I run the following:

document.styleSheets

I get an object containing some stylesheets.

If I clone the current document like this:

const clone = document.implementation.createHTMLDocument ();
clone.documentElement.innerHTML = document.documentElement.innerHTML;

And then run the following:

clone.styleSheets

I no longer get the stylesheets. How can I overcome this issue? I can't actually render the content of the cloned document anywhere.

As a shoddy workaround, you could set the cloned document's stylesheets to the previous document's stylesheets.

This may or may not work depending on how js deepcloning works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM