zoukankan      html  css  js  c++  java
  • 知识点---js监听手机返回键,回到指定界面

     方法一、

    $(function(){ 
    pushHistory(); 
    window.addEventListener(“popstate”, function(e) { 
    window.location = 返回的地址 
    }, false); 
    function pushHistory() { 
    var state = { 
    title: “title”, 
    url: “#” 
    }; 
    window.history.pushState(state, “title”, “#”); 
    } 
    });

    方法二、JS监听手机的物理返回键

    if(window.history && window.history.pushState) {
        $(window).on('popstate', function() {
            var hashLocation = location.hash;
            var hashSplit = hashLocation.split("#!/");
            var hashName = hashSplit[1];
            if(hashName !== '') {
                var hash = window.location.hash;
                if(hash === '') {
                    alert("你点击了返回键");
                }
            }
        });
        window.history.pushState('forward', null, './#forward');
    }

    方法三、JavaScript监听手机物理返回键

    pushHistory(); 
     
            window.addEventListener("popstate", function(e) { 
                window.location = 'http://www.baidu.com';
            }, false); 
     
            function pushHistory() { 
                var state = { 
                    title: "title", 
                    url: "#"
                }; 
                window.history.pushState(state, "title", "#"); 
            }
  • 相关阅读:
    Postfix邮件服务
    Python
    LVS
    MFS
    Apache
    Zookeeper集群 + Kafka集群 + KafkaOffsetMonitor 监控
    shell 检测安装包
    shell ssh 批量执行
    shell 判断脚本参数
    bzoj 1500 修改区间 splay
  • 原文地址:https://www.cnblogs.com/liaohongwei/p/10769230.html
Copyright © 2011-2022 走看看