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');  
    } 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章