11

My matches scheme:

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

So if the user went to a webpage (like https://stackoverflow.com/questions) then added #epic it would go to https://stackoverflow.com/questions#epic but would have #epic on the end of the URL, which would activate the content script silly.js.

That's what's supposed to happen, but that doesn't work.

Community
  • 1
  • 1
Alex
  • 1,035
  • 3
  • 16
  • 31
  • I don't think matching against the `hash` is supported. You could always match against `http://stackoverflow.com/questions*` and then check for the hash in your script instead. – BeardFist Apr 11 '13 at 21:46
  • Thats what I was thinking, but I didnt know for sure. Thanks – Alex Apr 11 '13 at 21:51

1 Answers1

22

See Content scripts, Match Patterns.
Match patterns do not operate on the fragment portion of a URL.

To restrict a content script to a given hash, use the include_globs and/or exclude_globs properties.

For example, in this case you might use:

"content_scripts" :     [ {
    "matches" :         [
        "*://stackoverflow.com/questions/*"
    ],
    "include_globs" :   ["*#epic*"],
    "js" :              ["silly.js"]
} ],
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
Brock Adams
  • 90,639
  • 22
  • 233
  • 295