移动端如何解决页面返回上次浏览位置问题

时间:2020-07-15 13:52:08   收藏:0   阅读:79
function pushHistory() {
        var state = {};
        state = {
            // title: "itGrade",
            自定义参数:自定义参数
        };
        console.log(state);
        window.history.pushState(state, null, "#");
    }

    // 在需要监听的页面执行该方法 自动监听页面返回操作
    window.addEventListener("popstate", function(e) {
        console.log(window.history);
        var state = window.history.state;
        console.log(state);
        if(state){
           //对应pushHistory 中的state的参数处理数据
        }else{
            window.history.go(-1);
        }
    }, false);

 

原文:https://www.cnblogs.com/-lin/p/13304693.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!