ajax能无刷新更新数据,可是不能更新urlhtml
HTML5的新API: window.history.pushState, window.history.replaceStateajax
用户操做history,点击前进后退按钮会触发popstate事件。浏览器
这些方法能够协同window.onpopstate
事件一块儿工做。url
改变url的demospa
本页是foo.html,url改变成bar.html,内容却不变code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <button onclick="changeUrl()">按钮</button> <script> function changeUrl() { var stateObj = {foo: 'bar'}; window.history.pushState(stateObj, 'page 2', 'bar.html'); // 这将让浏览器的地址栏显示http://mozilla.org/bar.html,但不会加载bar.html页面也不会检查bar.html是否存在。 } </script> </body> </html>