我试图做一个改变页面样式表的扩展。我更改了一些样式,例如背景颜色,但我无法更改整个样式表
manifest.json 文件
{
"name": "change stylesheet",
"version": "1.0",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_title": "Set this page's style",
"default_icon": "icon.png",
"popup": "popup.html"
}
}
popup.htm中java脚本调用部分
function click() {
chrome.tabs.executeScript(null,
{code:"document.getElementById('stylesheet').href = 'style1.css'"});
window.close();
}
最佳答案
Susantha - 你只需要在 list 中包含你的 css 文件:
http://code.google.com/chrome/extensions/content_scripts.html
{
"name": "My extension",
...
"content_scripts": [
{
"matches": ["http://www.google.com/*"],
"css": ["mystyles.css"],
"js": ["jquery.js", "myscript.js"]
}
],
...
}
您将需要使用 !important
覆盖现有样式,并像往常一样遵循样式的先例。如果有内联样式,那么你可能需要用js代码重写它。
关于javascript - 在 chrome 扩展中更改页面样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6891420/