javascript – 如何触发Chrome扩展程序,URL中给定哈希的内容脚本?

前端之家收集整理的这篇文章主要介绍了javascript – 如何触发Chrome扩展程序,URL中给定哈希的内容脚本?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的比赛计划:
"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.匹配模式不适用于URL的 queryfragment部分.

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

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

"content_scripts" :     [ {
    "matches" :         [
        "*://stackoverflow.com/questions/*"
    ],"include_globs" :   ["*#epic*"],"js" :              ["silly.js"]
} ],
原文链接:https://www.f2er.com/js/158427.html

猜你在找的JavaScript相关文章