gpt4 book ai didi

jquery - 带有 window.history.pushState 和后备的跨浏览器 jquery ajax 历史记录

转载 作者:行者123 更新时间:2023-12-03 21:31:23 25 4
gpt4 key购买 nike

我想使用 jQuery 和 AJAX 以跨浏览器的方式实现导航历史记录。我的方法是使用window.history.pushState并回退到哈希 url /#!/url在不支持window.history.pushState的浏览器中。

例如:

<a href="/home">home</a>
<a href="/about">about</a>
<a href="/contact">contact</a>

在支持window.history.pushState的浏览器上,单击这些链接之一应将地址更改为 http://domain.com/home,无需刷新页面。 , http://domain.com/about等当浏览器不支持window.history.pushState时,它应该使用片段标识符,即: http://domain.com/#!/home , http://domain.com/#!/about .

<小时/>

更新:根据此处的反馈,我已实现 Ajax SEO ( git ) 使用 jQuery Address对于旧浏览器的 HTML5 History API,回退到 /#!/url .

最佳答案

// Assuming the path is retreived and stored in a variable 'path'

if (typeof(window.history.pushState) == 'function') {
window.history.pushState(null, path, path);
} else {
window.location.hash = '#!' + path;
}

关于jquery - 带有 window.history.pushState 和后备的跨浏览器 jquery ajax 历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4250553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com