Is there any way to bookmark or link to an HTML page (which I am not author of) without having an anchor in the html code ?
I want the page to get scrolled down to a
If everything else fails, you can use get the query from the window.location
, use jQuery to get the DOM element, ask for it's position and scrollTop
to move there (see jQuery scroll to element)
The Firefox extension "Web Marker" does exactly what you want.
https://addons.mozilla.org/en-US/firefox/addon/web-marker/
You can find its source code and documentation here:
http://liveurls.mozdev.org/tech.html
You only need to have the appropriate id attribute on an element to use it like a bookmark...
<a href="#test">Test</a>
...
<p id="test">Hello world</p>
See the W3C specification: Anchors with the id attribute
Older specifications also allowed navigation based on the name
attribute, but this attribute has been removed from the latest HTML specifications (but if there is a name
attribute it may be used in the same way as an id
attribute).
If there is no id
or name
attribute where you wish to navigate to, there is no way of navigating to the specific point within the page, only to the page itself. In this case you may want to quote the pertinent information and supply a citation with a link or perhaps ask the author if they would add an id
.
Just in case anyone is still seeking a solution... AnchorMe addon from firefox just solved this for me. Ctrl + double click your desired destination and voila.
There is a relatively recent W3C Working Group Note on Selectors and States which would allow linking to selected text.
Here is a Firefox webextension partially implementing the link format (allowing you to "create" a link, based on the selection, as well as, obviously, open such a link, highlighting the correct selection):
https://addons.mozilla.org/en-US/firefox/addon/precise-links/
As of 2019 it seems to work fine.
Its source code is available here.
It's the year 2020, and now there is a draft by WICG for Text Fragments, and now you can link to text on a page as if you were searching for it by adding the following to the hash
#:~:text=<Text To Link to>
Working example on Chrome Version 81.0.4044.138
:
Click on this link Should reload the page and highlight the link's text