Can I inject a CSS file programmatically using a content script js file?

前端 未结 3 1611
感情败类
感情败类 2020-12-08 08:04

Can I inject a CSS file programmatically using a content script js file?

It is possible for me to inject the css when the js file is linked to my popup.html. The pro

3条回答
  •  难免孤独
    2020-12-08 08:37

    You can programmatically create a new tag and add it to the section just like JS files are loaded dynamically.

    var link = document.createElement("link");
    link.href = "http://example.com/mystyle.css";
    link.type = "text/css";
    link.rel = "stylesheet";
    document.getElementsByTagName("head")[0].appendChild(link);
    

    Here's an article on the topic.

提交回复
热议问题