javascript - Injecting StyleSheet Object into Iframe -
is possible page's style sheet object using stylesheet api , inject iframe had page's html? don't have css files. assuming happening on same domain.
you can iterate document.stylesheets, create <link> element href set href of current cssstylesheet, append <link> element body of <iframe> .contentdocument
const sheets = document.stylesheets; const iframe = document.queryselector("iframe"); console.log(iframe.contentdocument.head) (let {href} of sheets) { const link = document.createelement("link"); link.href = href; link.rel = "stylesheet"; iframe.contentdocument.body.appendchild(link) }
Comments
Post a Comment