zoukankan      html  css  js  c++  java
  • H5 应用程序返回button的js代码设计,设计仿stack

    history.back();

    该代码具有天然的缺陷,二手知道,于H5应用,尤其是模仿移动应用程序时,,这是不够。

    在放大期js为了实现类似特征,请轻喷。

    大笑


    不多说,上代码:

    /**
     * Created by piggsoft@163.com on 2015/5/28.
     */
    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);


    在须要实现back的地方调用

    historyUtils.back();



    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    rowid去重(转)
    Oracle中 row_number() over()分析函数(转)
    oracle分页计算公式
    vue 生产环境和线上环境配置
    vue postcss 样式等比缩放
    element-ui 表单输入手机号验证是否注册或者存在
    使用vue-qr 生成 二维码
    vue下载excel文件,后台传过来的是文件流解决办法
    前端请求接口发送的路径用域名代替ip
    将本地端口映射子域名
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4811519.html
Copyright © 2011-2022 走看看