获取链接以转到其他页面上的特定部分 [英] Getting a link to go to a specific section on another page

查看:87
本文介绍了获取链接以转到其他页面上的特定部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个非常基本的问题,所以希望有人能帮助这个困乏的编码器。我在一个页面上有一个链接,需要转到另一个页面,但加载到另一个页面上的特定部分。



我以前使用bootstrap完成了此操作,但是他们把所有的编码都拿出来了,所以我需要知道如何从头开始。这里是我基于这个链接的标记(不是最好的资源,我知道): http://www.w3schools。 com / html / html_links.asp

  **第一页** 
**页面我链接到**
< div id =timelinename =timeline>。 ..< / div>

我可以用html做到这一点,还是需要一些javascript 。如果我需要通过js来完成它,它需要在目标页面上吗?

我相信你的例子已张贴使用HTML5,其中允许你跳转到任何 DOM元素与匹配的 ID 属性。为了支持旧浏览器,你需要改变:

 < div id =timelinename =timeline...> 

以旧格式:

 < a name =timeline/> 

然后,您可以导航到 /academics/page.html #timeline 并跳到该部分。



另外,请查看类似问题


This seems like a terribly basic question, so hopefully someone can help this sleepy coder out. I have a link on one page that needs to go to a different page, but load to a specific section on that other page.

I have done this before with bootstrap but they take all the 'coding' out of it, so I need to know how to do from scratch. Here is the markup I have based on this link (not the best resource, I know): http://www.w3schools.com/html/html_links.asp

**Page One**
<a href="/academics/page.html#timeline> Click here </a>
**Page I am linking to**
<div id="timeline" name="timeline"> ... </div>

Can I do this with just html, or do I need some javascript. If I need to do it via js, it needs to be on the target page right?

解决方案

I believe the example you've posted is using HTML5, which allows you to jump to any DOM element with the matching ID attribute. To support older browsers, you'll need to change:

<div id="timeline" name="timeline" ...>

To the old format:

<a name="timeline" />

You'll then be able to navigate to /academics/page.html#timeline and jump right to that section.

Also, check out this similar question.

这篇关于获取链接以转到其他页面上的特定部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆