Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为chrome扩展注入CSS_Javascript_Html_Css_Google Chrome - Fatal编程技术网

Javascript 为chrome扩展注入CSS

Javascript 为chrome扩展注入CSS,javascript,html,css,google-chrome,Javascript,Html,Css,Google Chrome,我对Chrome扩展开发还很陌生。我知道注入CSS是可能的。但是是否可以为特定的URL注入它呢。例如,每当我访问google.com时,CSS都会被注入 谢谢你的帮助!:) 您有两个选项,编程注入和内容脚本。这些名字听起来可能非常复杂和可怕,但别担心;) 将在加载页面时自动注入自身。除了编写脚本之外,您所需要做的就是在manifest.json中指定如下内容: { "name": "My extension", "version": "1.0", "manifest_version"

我对Chrome扩展开发还很陌生。我知道注入CSS是可能的。但是是否可以为特定的URL注入它呢。例如,每当我访问google.com时,CSS都会被注入


谢谢你的帮助!:)

您有两个选项,编程注入和内容脚本。这些名字听起来可能非常复杂和可怕,但别担心;)

将在加载页面时自动注入自身。除了编写脚本之外,您所需要做的就是在manifest.json中指定如下内容:

{
  "name": "My extension",
  "version": "1.0",
  "manifest_version": 2,
  "content_scripts": [
    {
      "matches": ["http://www.google.com/"], //where your script should be injected
      "css": ["css_file.css"] //the name of the file to be injected
    }
  ]
}
这应该在每次加载google.com时注入CSS

你的另一个选择是使用。 如果您希望仅在某些时候(通常是从后台页面)注入代码,这可能非常有用。要做到这一点,您可以使用。在这种情况下,您的舱单中需要:

{
  "name": "My extension",
  "version": "1.0",
  "manifest_version": 2,
  "background_page": "myBackground.html", //if you want to inject it from a background page
  "permissions": [
    "background", //if you want to inject it from a background page
    "http://www.google.com/" // host permission to google
  ]
}
祝你好运