现在的位置: 首页 > 综合 > 正文

谷歌浏览器 引入插件内css

2013年10月04日 ⁄ 综合 ⁄ 共 825字 ⁄ 字号 评论关闭
//引入插件内css
//cssurl = ./meun/meun.css
function 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/*"
    ],

  

抱歉!评论已关闭.