最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Link that scrolls to position - Stack Overflow

programmeradmin0浏览0评论

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:

"A Google project headed by Vic Gundotra"

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

Note: I 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?

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./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 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?

Share Improve this question edited Sep 6, 2011 at 19:14 James asked Sep 6, 2011 at 18:25 JamesJames 2352 gold badges3 silver badges8 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

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./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.

Two lines with two possible outes.
First the assumption:solution

wwww.example./page.html#blockOfTextID

DA.

If the conclusion is ("), yes, I do know what the syntax could be. You can try. . .

https://docs.github./en/pages/setting-up-a-github-pages-site-with-jekyll/testing-your-github-pages-site-locally-with-jekyll#building-your-site-locally

A second oute you can get also through a
solution:assumption line which may be, ("), i have tried but i am not able to pare

https://docs.github./en/pages/setting-up-a-github-pages-site-with-jekyll/testing-your-github-pages-site-locally-with-jekyll#building-your-site-locallyID
发布评论

评论列表(0)

  1. 暂无评论