1. 程式人生 > >【PHP】安卓手機監聽物理返回按鍵

【PHP】安卓手機監聽物理返回按鍵

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