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.
我希望特定的链接转到另一个页面上的某个标题。我知道如何在当前页面上执行此操作。
4 个解决方案
#1
34
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>
#2
4
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:
您只需结合链路的想法到另一个页面,与HREF = foo.html,并链接到其他元素在同一页上,与HREF =#吧,让喜欢#bar的片段后,立即写入引用其他页面的URL:
<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>
#3
2
You can add hash info in next page url to move browser at specific position(any html element), after page is loaded.
您可以在下一页网址中添加哈希信息,以便在加载页面后将浏览器移动到特定位置(任何html元素)。
This is can done in this way:
这可以通过这种方式完成:
add hash in the url of next_page : example.com#hashkey
在next_page的url中添加hash:example.com #sickkeykey
$( 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');
});
#4
0
Create an anchor:
创建一个锚点:
<a name="anchor" id="anchor"></a>
then link to it:
然后链接到它:
<a href="http://server/page.html#anchor">Link text</a>
#1
34
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>
#2
4
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:
您只需结合链路的想法到另一个页面,与HREF = foo.html,并链接到其他元素在同一页上,与HREF =#吧,让喜欢#bar的片段后,立即写入引用其他页面的URL:
<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>
#3
2
You can add hash info in next page url to move browser at specific position(any html element), after page is loaded.
您可以在下一页网址中添加哈希信息,以便在加载页面后将浏览器移动到特定位置(任何html元素)。
This is can done in this way:
这可以通过这种方式完成:
add hash in the url of next_page : example.com#hashkey
在next_page的url中添加hash:example.com #sickkeykey
$( 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');
});
#4
0
Create an anchor:
创建一个锚点:
<a name="anchor" id="anchor"></a>
then link to it:
然后链接到它:
<a href="http://server/page.html#anchor">Link text</a>