8

I'm trying to write a post with form fill tutorial. There are a lot of sources, but source pages doesn't provide anchors on pages.


So my question is , how to make links to concrete paragraphs of text on html pages?

Is it possible at all?

Are there any JavaScript tricks in the url to achieve that?


edit:

I need to make link to particular paragraph on external source. For example to paragraph beginning with words "The Navy traces its origins to the" on this Wikipedia's page

aparente001
  • 339
  • 2
  • 4
  • 19
2r2w
  • 1,384
  • 1
  • 12
  • 29
  • Do you mean, link to a particular place on the page *without* the use of [anchors](http://www.echoecho.com/htmllinks08.htm)? – Roddy of the Frozen Peas Aug 21 '12 at 18:53
  • If you're open to using jQuery, then this post might help: http://stackoverflow.com/questions/3432656/scroll-to-a-div-using-jquery – nashyura Aug 21 '12 at 18:56
  • @nashyura not even close. I need to make external link to source, it means on particular paragraph on external html page – 2r2w Aug 21 '12 at 18:58
  • 1
    You could probably use JavaScript to scroll to that part of the page, but this would be very fragile, because it would break if the sentence was reworded. – ThatMatthew Aug 21 '12 at 19:10
  • @ThatMatthew tell me how, cause my sources are official and probably not going to be changed – 2r2w Aug 21 '12 at 19:12
  • This looks helpful: http://stackoverflow.com/questions/5795299/javascript-find-text-on-page – ThatMatthew Aug 30 '12 at 18:43

3 Answers3

8

As of 2020, 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

Abderrahmane TAHRI JOUTI
  • 3,514
  • 2
  • 26
  • 43
5

You can only link to named anchors or elements with ids. If the target page has neither you are out of luck.

JJJ
  • 32,902
  • 20
  • 89
  • 102
  • thanks. but is that all? I know, that I can enumerate paragraphs on page. Is there a way to focus on particular paragraph using url? – 2r2w Aug 21 '12 at 19:16
  • 1
    If you want to do it using purely the URL only, there's nothing you can do. If you embed the page in an iframe you have a bit more control. – JJJ Aug 21 '12 at 19:21
  • maybe interesting. could you provide an example? – 2r2w Aug 21 '12 at 19:22
2

I just noticed, that you want this on external source. If there are ids, you can use this: http://jsfiddle.net/LCgge/

Kristóf Dombi
  • 3,927
  • 3
  • 18
  • 14