首页 > 不刷新页面实现更改 url 地址

不刷新页面实现更改 url 地址

看到一个叫 Product Hunt 的网站,点击任何一篇文章,url 都会变化,但页面并没有刷新,而且访问文章的网址,内容会展开,这是怎么实现的?


ie下会有问题吧


使用 hash 吧 window.location.hash


ajax 局部刷新


单页面应用的框架都有吧,就是一楼说的 history.pushState()和history.replaceState()


原理是利用HTML5引入的history.pushState()history.replaceState()方法.

HTML5 Demo: HTML5 History API
Manipulating History for Fun & Profit

Github项目: browserstate/history.js


pjax

这个实现ajax和history api的结合


移动端兼容还不太好


可以用hash

【热门文章】
【热门文章】