在Chrome、Safari、Firefox 4+和Internet Explorer 10以上可以实现
正文
实现代码如下:
/** * 时间:2019年8月18日 * 前端教程: https://www.pipipi.net/ */ function processAjaxData(response, urlPath){ document.getElementById("content").innerHTML = response.html; document.title = response.pageTitle; window.history.pushState({"html":response.html,"pageTitle":response.pageTitle},"", urlPath); } //你可以使用window.onpopstate来检测浏览器前进后退按钮 window.onpopstate = function(e){ if(e.state){ document.getElementById("content").innerHTML = e.state.html; document.title = e.state.pageTitle; } };