简体   繁体   English

链接到页面的不同部分/选项卡

[英]Link to different parts/tabs of a page

Have a look at http://keithloutit.com/#news 看看http://keithloutit.com/#news

I have a similar site, with all the content on the same page. 我有一个类似的网站,所有内容都在同一页面上。

I would like to know how to fetch the correct part of the url. 我想知道如何获取url的正确部分。 In this case it would be "news". 在这种情况下,它将是“新闻”。 I suppose its some regexp used on document.location.href ? 我想它在document.location.href使用了一些正则表达式? Hope you get the idea, otherwise ill try to elaborate. 希望您能明白,否则请尝试详细阐述。 Thanks 谢谢

The javascript on the page has to get the hash from the URL: 页面上的javascript必须从URL获取哈希:

window.location.hash

and then activate the currect tab. 然后激活当前选项卡。


Note: if you're merely linking to a part of your page that is not part of a tabular system, you don't need javascript. 注意:如果仅链接到不属于表格系统的页面的一部分,则不需要javascript。 The page will automatically scroll down to the element with that ID. 该页面将自动向下滚动到具有该ID的元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM