【发布时间】:2016-11-17 06:05:40
【问题描述】:
所以我想要实现的是有一个链接列表,点击其中任何一个都会将 div 的内容更改为“随便”。很简单,我已经做到了。
我遇到问题的部分是获取更改内容的某种永久链接。
say main domain is www.example.com
then you click link X and content Y shows up on the page
then the URL should change to www.example.com/SOMETHINGHERE
--all good so far--
then using the new link should take you to the site with the changed content
让我们获取一些示例代码:
<a href="something.html" class="linx" >Click me</a>
<a href="something2.html" class="linx" > Click me too</a>
<div id="loadhere"></div>
$('.linx').click(function (event) {
event.preventDefault();
$('#loadhere').load(this.href);
});
相当基本的东西。这就是它的工作方式。现在我用谷歌搜索了一下,似乎我需要使用历史 API 甚至 history.js 库。我稍微修改了一下,但我是一个新手,整个历史的事情有点混乱。
一个接近我想要实现的例子是Soulwire's personal website. 导航到实验部分,看看运行每个实验是如何工作的。
所以基本上我要问的是您是否可以通过给我一个示例或其他内容而不是链接文档来帮助我使用历史 API(如果这实际上是这样做的方式 - 我可能是错的),或者如果有其他方法我可以尝试实现这一点。
提前致谢。
【问题讨论】:
-
这个 SO question 可以帮助你。
-
window.history.pushState("object or string", "Title", "/new-url");
标签: javascript jquery ajax html5-history