//引入外掛程式內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/*" ],