js如何实现修改页面url不刷新页面

在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;
    }
};

 

(4)
上一篇 2019年8月18日 下午3:31
下一篇 2019年8月18日 下午3:44

相关推荐

发表回复

登录后才能评论