首页 > 编程知识 正文

js返回上一级页面,返回上一级页面快捷键

时间:2023-05-06 00:24:23 阅读:243613 作者:60

var historyUtils = { add : function (url) { var historyArray = historyUtils.getLocal(); if (!historyArray) { historyArray = []; } var currentPage = historyArray.pop(); if (currentPage && currentPage == url) { //do nothing } else if (currentPage){ historyArray.push(currentPage); //历史里面没有现在传入的url,在加回去 } historyArray.push(url); historyUtils.saveLocal(historyArray); }, back : function() { var historyArray = historyUtils.getLocal(); var currentPage = historyArray.pop();//去掉当前页面,pop取最后,类似stack var history = historyArray.pop(); if (!history) {//没有历史页面 historyUtils.add(currentPage);//将当前页面加入回数组中 return; } historyUtils.saveLocal(historyArray); window.location.href = history; }, getLocal : function() { var result = window.sessionStorage.getItem(historyUtils.key); if (!result) { return null; } return JSON.parse(result); }, saveLocal : function(data) { window.sessionStorage.setItem(historyUtils.key, JSON.stringify(data)); }, init : function() { historyUtils.saveLocal([]); }, key : "_history_"};historyUtils.add(window.location.href);

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。