改变页面样式表在chrome扩展
changing page style sheet in chrome extension
我试图做一个扩展来改变页面样式表。我可以改变一些样式,比如背景色但我不能改变整个样式表
清单。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"
}
}
部分,Java脚本调用在popup.htm
function click() {
chrome.tabs.executeScript(null,
{code:"document.getElementById('stylesheet').href = 'style1.css'"});
window.close();
}
Susantha -你只需要在清单中包含你的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代码重写它。
相关文章:
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 从选项页面更新chrome扩展清单权限
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- Chrome扩展:遍历不同的页面并收集数据
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 可以从Chrome扩展修改窗口对象吗
- 从popup.js|Chrome扩展访问DOM
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 在Chrome扩展内部输出Google API调用
- 检查是否存在使用chrome扩展的javascript库
- 从Chrome扩展访问Google Cloud SQL数据库
- Chrome扩展,Chrome.tabs.query的结果未定义
- 为tweet构建chrome扩展
- 在chrome扩展中使用AJAX获取目录中的文件数