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) } 

plnkr http://plnkr.co/edit/xl544x0fmn0wdnjiool7?p=preview


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -