我的匹配方案:
"content_scripts" : [
{
"matches" : [
"https://stackoverflow.com/questions#epic*"
],
"js" : ["silly.js"]
}
],
因此,如果用户转到网页(如 https://stackoverflow.com/questions),然后添加 #epic
,它将转到 https://stackoverflow.com/questions#epic但是在 URL 的末尾会有 #epic
,这将激活内容脚本 silly.js
。
这是应该发生的事情,但这是行不通的。
最佳答案
参见 Content scripts, Match Patterns .
匹配模式不在 fragment 上运行URL 的一部分。
要将内容脚本限制为给定的哈希值,请使用 the include_globs
and/or exclude_globs
properties .
例如,在这种情况下您可以使用:
"content_scripts" : [ {
"matches" : [
"*://stackoverflow.com/questions/*"
],
"include_globs" : ["*#epic*"],
"js" : ["silly.js"]
} ],
关于javascript - 如何触发 Chrome 扩展,URL 中给定哈希的内容脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15959090/