22

Recently, I noticed that sometimes when I search on Google, Google can highlight the relevant part of the webpage by attaching a hash fragment like this:

https://example.com/#:~:text=You%20may%20use%20this%20domain%20in%20literature%20without%20prior%20coordination%20or%20asking%20for%20permission.

And it will scroll to "You may use this domain in literature without prior coordination or asking for permission." and highlight it.

I wonder what kind of magic is this, is it part of any RFC or Web standard, or maybe it's Google Chrome that I'm using? Or is it some kind of JavaScript patch injected/provided by Google?

zypA13510
  • 1,092
  • 1
  • 10
  • 28
  • It is application-dependent. No assigned “standard” meaning. – user2864740 Jun 04 '20 at 03:05
  • 2
    https://www.howtogeek.com/658842/how-to-use-google-chromes-new-deep-linking-feature/ – Phil Jun 04 '20 at 03:07
  • 3
    FWIW, there are some fragment identifier “proposals” listed on https://en.wikipedia.org/wiki/Fragment_identifier and implemented in different clients/programs. – user2864740 Jun 04 '20 at 03:11
  • 3
    @user2864740 yeah seems to be on its way for more widespread adoption... https://wicg.github.io/scroll-to-text-fragment/ – Dennis Hackethal Oct 26 '20 at 05:48
  • This question is about `:~:` specifically, not `:~:text=`. This is a separate question and not a duplicate. `:~:` itself is not addressed in the linked question. Reopen. – Zaz Feb 17 '22 at 21:41
  • The answer to this question is that `:~:` is [the fragment directive](https://wicg.github.io/scroll-to-text-fragment/#the-fragment-directive): A [magic string](https://en.wikipedia.org/wiki/Magic_string) that tells the browser to remove everything after it to avoid compatibility issues with webpage code that uses the fragment. – Zaz Feb 17 '22 at 21:49

0 Answers0