JS 监听手机返回键,回到指定界面

<script>
    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 === '') {
                            // 这里跳转页面
                            console.log("你点击了返回键");
                        }
                }
        });
        window.history.pushState('forward', null, './#forward');
    }
</script>

 

本文转载自: https://www.cnblogs.com/liaohongwei/p/10769230.html

posted @ 2020-06-05 17:59  本溢  阅读(152)  评论(0)    收藏  举报