Smarter Than 'Ctrl+F': Linking Directly to Web Page Content
144 comments
·October 25, 2024lolinder
kenrick95
I was surprised too, cause initially they had some issues with the proposal [1], resolved it few years later [2], and finally implemented it since last year [3]
[1] https://github.com/mozilla/standards-positions/issues/194#is...
[2] https://github.com/mozilla/standards-positions/issues/194#is...
gertrunde
In all honesty, I've hated this feature with a passion ever since it appeared.
If it was simply a matter of being used in the way outlined in the article, when someone creates a a link that references a particular piece of text, then fine, someone has deliberated intended the link to behave like that.
And then we have the lovely folk at Google search... who think it's fun to drag my attention off to a random part of a page that isn't where I want to be, forcing me to right-click, remove annotation and scroll back up to the top of the page.
That doesn't seem like a massive hardship, but it gets quite frustrating when multiplied over the many searches done in a day/week/month.
thebytefairy
Isn't the reason it highlights that from search because that was your search term? That's what I've seen, in which case I prefer that it does draw my attention to that string
KTibow
That sounds annoying, even if the only work required was to press `Home`. Does this only happen with the featured snippets?
coryfklein
Sounds like your problem is with a Google product more so that the browser feature itself. I for one can't wait to start using these kinds of deep links. I love when websites have "copy link to header" buttons, but even when they do I often want to link to a particular sub-paragraph or sentence as a citation... and now I can!
rakoo
Unsurprisingly this is something you could do in Plan 9:
/path/to/file:/from.*to
opens the file and sets the selection to the range of text between "from" and "to". Bonus: you can use regular expressions.It pains me to see the web having strayed so far from its focus on interlinking. It's easy to make a parallel when on one side device makers have taken control back by removing access to files and putting applications first (this is the only model on mobile), to the point that those makers have enormous control over apps' existence, and the web where applications are now the only way to access content, to the point that content may or may not available if the right API exists.
c-linkage
The world wide web has moved beyond documents to apps. With apps there is nothing left to interlink.
gradientsrneat
vim users may be pleased to know that this can be done when vim is invoked from the command line, via the +/{pat} option. Sadly doesn't work for gF (yet).
See also hyperbole for emacs.
shakna
Super unintuitive that the HTTP header a site can set, to disable this, is:
Document-Policy: force-load-at-top
dspillett
Unfortunately, not supported away from chromium derived browsers ATM: https://caniuse.com/document-policy (though given current market shares that sill means the majority of your user base is likely to have support)
pimlottc
Does that disable the highlighting too or just the auto-scroll behavior?
shakna
I think we're a long way from standardisation just now. So the behavior of the header is verging on the undefined territory. It might do something. It might even order a grape soda. Hopefully it does what you want. It might not.
fbn79
In Google Chrome select text, right click and click "copy link to highlight". It create a link with ~:text=
thinkingemote
Programmatically what can a developer do with this?
I see that there is a method and an object to see if its enabled or not. And there is a way to get the whole fragment which can be parsed.
Are there methods to see whether some text in the fragment was actually highlighted or not? Are there methods to programmatically select text?
Could there be a way to, for example, draw a rectangle around the highlighted section, to get the coordinates of the text, to read out the selected text, to store what words people select and link to etc
Maybe it's an external link about headline news and the news title got changed by the editor. Maybe the developer may want to change the selection to the edited title so the user isn't surprised. Maybe its a multi lingual blog post and the user links using another language... etc etc
xp84
Since you have access to the URL fragment in JS, you should be able to do any of that manually even if there isn't a special API to use. The easiest thing to do would be to check for this specially-crafted fragment in the URL and store it.
I think though that this is a pretty niche feature though, so it's unlikely to be a big source of data. In my experience, the median sophistication web user has discovered that the browser's Back button exists and can Open in New Tab. Bookmarks, zoom, ctrl-F are all too confusing. A feature that requires right-clicking may as well be black magic to most people.
pbiggar
I use these for footnotes, eg in [1] which had a lot of footnotes. Ghost and other blogs don't support footnoting well afaict. Sometimes I miss restructured text, which did this quite well, markdown alas does not.
donohoe
I built something like this for The New York Times and it was one of the more fun projects I did there.
The thing I really hoped this "new" version would account for is when text changes and having links survive minor edits/changes. Perhaps I missed it and it does.
- https://github.com/NYTimes/Emphasis
- https://open.nytimes.com/emphasis-update-and-source-6ffac5e6... (2011)
cxr
There's no such thing as "text changes". Only publishers lying about URLs and response bodies. This should stop.
donohoe
Um. This is where I can attest that you are 100% wrong. Sorry.
It does. Text changes. It is not frequent, often minor. Corrections can be more significant depending on their nature.
cxr
You're not sorry. You're just insincere.
This isn't Harry Potter. Text doesn't change.
New revisions are issued, but the text changes no more in those instance than it does when a publisher releases an update to a print work originally published in 1985 with a second edition. The text of the second edition might differ from the first edition, but the first edition's text doesn't change, and the first edition is still the first edition (instead of the first and second editions being synonymous). And the publishers of the print editions could try lying about the identity of these two distinct manifestations the way that online publishers lie about the identities of the works they publish, but no amount of lying about it makes the lie true.
Text doesn't change.
ahmadalfy
Wow, this is interesting to see. Thanks for sharing. This was long before any standardization in this area
jiri
It would be nice to have similar feature like this, but to highlight rectangle (instead of text) on the page to focus viewer on some specific area. I send screenshots with highlight quite often.
rafram
Pretty difficult to specify a rectangular region within reflowable content. It would need to be anchored by element edges, but if the algorithm chooses bad anchor elements or they reflow in weird ways (a layout that goes from horizontal to vertical on small screens, for instance), everything breaks.
tough
you could try and target a div to highlight
bandie91
or every document on the web may have hierarchical semantic structure, so you can link/refer to a heading in any depth. eg #1 → first chapter; #1.2 → first chapter second heading; #1.2.1 → first chapter second heading first paragraph; #1.2.1.5 → first chapter second heading first paragraph 5th sentence. it won't neccessary be chapter-heading-paragraph-sentence 4-fold structure - just wanted to illustrate in conventional language -, but any level of structure.
…why not put a css-selector in the link?
al_borland
Every time I run across this I think about how useful it is, then forget it exists and never actually use it.
ninalanyon
Looks like Firefox is lagging behind. It understands the url but there doesn't seem to be a way to create it from the UI. Chromium has "Copy link to highlight" in the right click/context menu but Firefox 131.0.3 doesn't. There is an add-on though: https://addons.mozilla.org/en-US/firefox/addon/link-to-text-...
andai
I've noticed that Google inserts this into result links sometimes, taking you to the relevant part of the page.
Today I learned that Firefox finally implemented these! They don't mention this in the article, but that's new this month—for the longest time Chrome supported it but it isn't in the standard and Firefox didn't include it. Safari got it 2 years later, but Firefox held out for a while.
I'm normally not a fan of Chrome unilaterally adding something to the platform, but this has been a long time coming.