Is there any way to bookmark or link to a section of a page without an anchor?

烈酒焚心 提交于 2019-11-30 06:37:02

问题


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 particular section when accessed from a bookmark or hyperlink even if there is no anchor tag in the destination page.

Note : the destination page has an anchor tag as "foo" then bookmark like http:/...hello.html#foo will not only take the user to hello.html but also automatically scroll down to the section of the page so that the anchore tag "foo" is at the top of the screen


回答1:


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.




回答2:


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)




回答3:


The Chrome extension Any Link does exactly what you want.

It enables you to create links to any selected texts in any web pages with only 3 steps:

  1. select the text you want to link/highlight
  2. right click to show the context menu
  3. click the link to text menu item.

The link to the text will be generated at background and copied to clipboard right away, you can then paste the link anywhere or make a bookmark with the link.

You can find the extension here: https://chrome.google.com/webstore/detail/any-link-safereliable-lin/mpflpgaobfpjcpefkdnpalfdodifkkgc




回答4:


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



来源:https://stackoverflow.com/questions/7983290/is-there-any-way-to-bookmark-or-link-to-a-section-of-a-page-without-an-anchor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!