How to link to a
on another page?

2020-02-17 05:48发布

I'd like that a specific link goes to a certain header on another page. I know how to do it on the current page.

标签: html
4条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-02-17 06:03

Create an anchor:

<a name="anchor" id="anchor"></a> 

then link to it:

<a href="http://server/page.html#anchor">Link text</a>
查看更多
戒情不戒烟
3楼-- · 2020-02-17 06:12

Take a look at anchor tags. You can create an anchor with

<div id="anchor-name">Heading Text</div>

and refer to it later with

<a href="http://server/page.html#anchor-name">Link text</a>
查看更多
劳资没心,怎么记你
4楼-- · 2020-02-17 06:15

You can add hash info in next page url to move browser at specific position(any html element), after page is loaded.

This is can done in this way:

add hash in the url of next_page : example.com#hashkey

$( document ).ready(function() {

  ##get hash code at next page
  var hashcode = window.location.hash;

  ## move page to any specific position of next page(let that is div with id "hashcode")
  $('html,body').animate({scrollTop: $('div#'+hascode).offset().top},'slow');

});
查看更多
相关推荐>>
5楼-- · 2020-02-17 06:23

You simply combine the ideas of a link to another page, as with href=foo.html, and a link to an element on the same page, as with href=#bar, so that the fragment like #bar is written immediately after the URL that refers to another page:

<a href="foo.html#bar">Some nice link text</a>

The target is specified the same was as when linking inside one page, e.g.

<div id="bar">
<h2>Some heading</h2>
Some content
</div>

or (if you really want to link specifically to a heading only)

<h2 id="bar">Some heading</h2>
查看更多
登录 后发表回答