开发者

Link that scrolls to position

开发者 https://www.devze.com 2023-04-03 05:47 出处:网络
Is it possible to create a link to any web page and scroll to the position of the first instance of a block of text?

Is it possible to create a link to any web page and scroll to the position of the first instance of a block of text?

eg:

http://techcrunch.com/2011/09/06/google-api-launch-still-months-away/#scrollto"A Google project headed by Vic Gundotra"

and this will scroll to some where half way of the page.

Note: I 开发者_StackOverflow中文版don't have control over the linked page, it could be any page on the web. Is there any javascript trick that will allow me to do what I described?


I don't have control of the linked page

All you can do is link to an anchor/ID on the page. If the first block of text on the targeted page has an ID attribute, then you can link to that:

wwww.example.com/page.html#blockOfTextID


No, you can only link to parts of the page that already have named anchors on the page.

Link that scrolls to position

Which links to my answer to your question. But only works, because Stack Overflow has HTML like:

<a name="7324427"></a>

Above every answer to make this possible.


Yes, what you're looking for is a Text Fragment:

Text Fragments

I know this is an old question, but the answers pre-date this technology, and I was researching a similar issue and noticed this came up as a top result.

0

精彩评论

暂无评论...
验证码 换一张
取 消