栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

我的CSS没有通过我的内容脚本注入

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

我的CSS没有通过我的内容脚本注入

样式表实际上是注入的,但没有应用,因为其他样式会覆盖规则。要使规则生效,您可以选择以下选项:

  1. 增加CSS规则的特异性。
  2. 在每个规则后缀

    !important

    #test {margin: 0 10px !important;background: #fff !important;padding: 3px !important;color: #000 !important;

    }

  3. 通过内容脚本注入CSS:

myscript.js

    var style = document.createElement('link');style.rel = 'stylesheet';style.type = 'text/css';style.href = chrome.extension.getURL('myStyles.css');(document.head||document.documentElement).appendChild(style);

manifest.json

    {  "name": "Extension",  "version": "0",  "description": "",  "manifest_version": 2,  "permissions": ["tabs", "http:/*", "file://*", "https:/*"],        "js": ["myscript.js"],        "all_frames": true    }  ],  "web_accessible_resources": ["myStyles.css"]}

web_accessible_resources
当清单版本2处于活动状态时,最后一个键是必需的,以便可以从非扩展页面读取CSS文件。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/405080.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号