Textual content fragments are a manner for net hyperlinks to specify a phrase or phrase a browser ought to spotlight on the vacation spot web page. Google Chrome added assist for them in model 80 (launched in February 2020).
For instance, opening the hyperlink oleb.internet/2020/swift-docker-linux/#:~:textual content=operating,container in Chrome ought to spotlight the primary heading of the article:
The apparent use case is search engines like google and yahoo: whenever you click on a hyperlink in a search end result, the browser would routinely spotlight your search time period(s) on the vacation spot web page.
I’ve at all times wished this function. I usually discover myself visiting a web page from a search engine, solely to instantly hit
However textual content fragments produce other makes use of past search engines like google and yahoo:
-
Linking to a specific sentence or paragraph of an extended doc. I’d use this on a regular basis when linking to API documentation or discussion board posts. “Regular” URL fragments solely work for anchors the writer of the vacation spot web page created upfront, and readers often can’t see what anchor tags can be found on a web page.
-
Sharing a selected portion of a web page. Browsers might facilitate this by providing to incorporate a textual content fragment within the URL when sharing a hyperlink to a textual content choice.
Right here’s the pattern URL from above as soon as extra:
https://oleb.internet/2020/swift-docker-linux/#:~:textual content=operating,container
This half is the textual content fragment:
#:~:textual content=operating,container
This fragment finds the primary point out of “operating” (case-insensitive) on the web page and highlights all the things from that time till it finds “container”. There are just a few extra variants of the syntax. Learn the textual content fragments draft spec for particulars.
Search phrases might include delicate data that customers don’t wish to share with the vacation spot server. For good purpose, search engines like google and yahoo stopped reporting the person’s search phrases within the referer header a very long time in the past as a part of the widespread transfer to HTTPS. It could be dangerous if a brand new function reintroduced this outdated information leak.
The spec considers this difficulty. Textual content fragments are designed to be purely a browser-level function — they’re not uncovered to JavaScript code. This screenshot demonstrates that doc.location.hash
is clean as a result of Chromium stripped the textual content fragment away:
I feel this the suitable habits, however the spec authors appear to be contemplating altering it again as a result of it could constrain some respectable use circumstances and since JavaScript can already decide what parts of a web page a person is studying by monitoring the viewport rect. I don’t know — exposing a delicate search time period appears extra invasive to me than the scroll place.
It’s value noting that the privateness concern exists for browsers that don’t assist textual content fragments: they may deal with the gibberish as a standard URL fragment, which might simply be parsed with a little bit of JavaScript.
As a precaution, search engines like google and yahoo and comparable websites ought to in all probability solely embrace textual content fragments of their hyperlinks if the person’s browser helps the function (window.location.fragmentDirective
).
Chrome is at the moment the one browser with textual content fragment assist. From what I’ve learn, the WebKit and Firefox groups are typically supportive of the concept however have some reservations about particular design selections.
I hope this or one thing prefer it turns into broadly supported within the close to future.
Replace June 22, 2020: I uncared for to say fragmentations, an IndieWeb initiative that goals to unravel the identical drawback and is a minimum of six years outdated. This function makes use of regular URL fragments and client-side JavaScript to seek out the matching textual content on the vacation spot web page (which is barely needed as a result of there’s no native browser assist, in fact).