【问题标题】:Is it possible to have two separate css files in the manifest, affecting two separate domains?清单中是否可以有两个单独的 css 文件,影响两个单独的域?
【发布时间】:2013-05-05 16:47:31
【问题描述】:

您可以拥有以下内容:

  "content_scripts": [
    {
      "css": [ "style1.css" ],
      "matches": ["http://domain1.com"],    
      "run_at": "document_end"
    }
  ],

但是可以为两个或多个域执行此操作吗? 如下所示: (我知道这是行不通的,但为了举例)

  "content_scripts1": [
    {
      "css": [ "style1.css" ],
      "matches": ["http://domain1.com"],    
      "run_at": "document_end"
    }
  ],
  "content_scripts2": [
    {
      "css": [ "style2.css" ],
      "matches": ["http://domain2.com"],    
      "run_at": "document_end"
    }
  ],

那么这可能吗?如果可以,怎么做?

【问题讨论】:

    标签: javascript google-chrome google-chrome-extension manifest


    【解决方案1】:

    当然,您可以根据需要注入任意数量的不同的。语法是这样的:

    "content_scripts": [
    {
      "css": ["style1.css"],
      "matches": ["http://domain1.com"]
    },
    {
      "css": ["style2.css"],
      "matches": ["http://domain2.com"]
    }]
    

    【讨论】:

    • @user2352308 是的,这是允许的。这就是为什么我用它来回答。另外,请注意它是如何带有 s 的 'content_scripts' 并且是一个数组,这意味着有多个空间。
    • 是的,它不允许这样做。 “无效端口”它说。 Could not load extension. Invalid value for 'content_scripts[1].matches[0]': Invalid port.
    • @user2352308 这可能是你放的东西的问题,而不是你放的方式。哪一行抛出了那个错误,那一行是什么?
    • 它不会把它扔到任何一行。我给了你错误。 编辑: 没关系我解决了这个问题。我有http:domain2.com反正看起来像解决方案!让我测试一下。
    猜你喜欢
    • 2022-06-16
    • 1970-01-01
    • 2021-01-20
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    相关资源
    最近更新 更多