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

javascript - Html href to a specific place in another page - Stack Overflow

programmeradmin1浏览0评论

How can I put an href tag with link to a specific h1 tag in another page? This is what I tried...

<a href="page2.html/subject 2">Move to page 2, section 1</a>

Thanks

How can I put an href tag with link to a specific h1 tag in another page? This is what I tried...

<a href="page2.html/subject 2">Move to page 2, section 1</a>

Thanks

Share Improve this question asked Nov 25, 2017 at 6:28 Dan SDan S 211 silver badge6 bronze badges 1
  • 2 Possible duplicate of How to navigate to a section of a page – ZerosAndOnes Commented Nov 25, 2017 at 6:33
Add a ment  | 

3 Answers 3

Reset to default 6

You can do something like this:-

<div id="anchor-name"> <h1>Heading goes here </h1></div>

and refer to it later with

<a href="http://server/page.html#anchor-name">Link text</a>

First of all you have to give unique id to h1 tag on page2.

<a href="page2.html/subject 2#firstH1">Move to page 2, section 1</a>

Where #firstH1 is the id given to h1

Add page link to href with additional reference to the id of the specific div containing the heading(h1).

<a href="page2.html#mydiv"> Click to move to next page heading </a>

Here, page2.html is the link to next page and mydiv is the id of the div in which h1 is present.

<div id="mydiv>
  <h1> My Heading </h1>
</div>

P.S: You can use the same approach to scroll to different parts on the same page.

Use target='_blank' if you want to open the next page in a new tab.

发布评论

评论列表(0)

  1. 暂无评论