【问题标题】:How to trigger a Chrome extension, content-script for a given hash in the URL?如何为 URL 中的给定哈希触发 Chrome 扩展、内容脚本?
【发布时间】:2013-04-04 06:09:27
【问题描述】:

我的匹配方案:

"content_scripts" : [
 {
   "matches" : [
     "https://stackoverflow.com/questions#epic*"
   ],
   "js" : ["silly.js"]
 }
],

因此,如果用户访问网页(如 https://stackoverflow.com/questions)然后添加 #epic,它将转到 https://stackoverflow.com/questions#epic,但在 URL 的末尾会有 #epic,这将激活内容脚本 @987654326 @。

这是应该发生的事情,但这不起作用。

【问题讨论】:

  • 我认为不支持匹配 hash。您总是可以匹配 http://stackoverflow.com/questions*,然后检查脚本中的哈希值。
  • 这就是我的想法,但我不确定。谢谢

标签: javascript google-chrome-extension manifest hashtag content-script


【解决方案1】:

Content scripts, Match Patterns
匹配模式不适用于 URL 的 fragment 部分。

要将内容脚本限制为给定的哈希,请使用the include_globs and/or exclude_globs properties

例如,在这种情况下,您可能会使用:

"content_scripts" :     [ {
    "matches" :         [
        "*://stackoverflow.com/questions/*"
    ],
    "include_globs" :   ["*#epic*"],
    "js" :              ["silly.js"]
} ],

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2021-06-15
    相关资源
    最近更新 更多