前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >js如何实现修改页面url不刷新页面

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

原创
作者头像
IT工作者
发布2022-01-25 10:34:35
8.4K0
发布2022-01-25 10:34:35
举报
文章被收录于专栏:程序技术知识程序技术知识

在Chrome、Safari、Firefox 4+和Internet Explorer 10以上可以实现

正文

实现代码如下:

代码语言:javascript
复制

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 正文
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档