Google瀏覽器 引入外掛程式內css

來源:互聯網
上載者:User
//引入外掛程式內css//cssurl = ./meun/meun.cssfunction includeCss(cssurl) {    //csspath = ./menu/    var localCssUrl = chrome.extension.getURL(cssurl);    $.get(localCssUrl, function (data) {        var csspath = localCssUrl.substr(0, localCssUrl.lastIndexOf("/"));        var data = data.replace(/\${csspath}/igm, csspath);                var styleInsert = document.createElement("style");        var styleContent = document.createTextNode(data);        styleInsert.type = "text/css";        if (styleInsert.styleSheet) styleInsert.styleSheet.cssText = styleContent.nodeValue;        else {            styleInsert.appendChild(styleContent);            document.getElementsByTagName("head")[0].appendChild(styleInsert)        }    });}// 使用方法includeCss("js/Contextmenu/Contextmenu.css");

使用方法css

.textpng {    background: url(${csspath}/images/icons/text.png) center no-repeat;     background-size:16px auto; }

最後還得在manifest.json中加入配置

 

   //js代碼可以訪問的資源   "web_accessible_resources": [   "js/Contextmenu/*"    ],

  

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.