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 === '') {
                //这里写 要做的操作
                var image = "";
                $("input[name='image[]']").each(function(){
                    if($(this).val() != ''){
                        image += $(this).val()+",";         
                    }
                });
                //删除图片操作
                if(image != ''){
                    $.ajax({
                           type: "POST",
                           url: "{:U('Person/checkStatusBackDelete')}",
                           data: {'image':image},
                           success: function(res){
                           }
                    });                 
                }
                //跳转
                window.location.href = "/Wechat/Person/my_robbing";
            }
        }
    });
    window.history.pushState('forward', null, './{$job.id}.html');
}
</script>

这儿 ./{$job.id}.html 指当前页面的后缀变量

原博主连接:http://www.cnblogs.com/prolovecui/p/6687392.html。侵删。

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,920评论 1赞 32
  • 官网 中文版本 好的网站 Content-type: text/htmlBASH Section: User ...
    不排版阅读 4,885评论 0赞 5
  • 概要 64学时 3.5学分 章节安排 电子商务网站概况 HTML5+CSS3 JavaScript Node 电子...
    阿啊阿吖丁阅读 10,053评论 0赞 3
  • ORACLE自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,299评论 0赞 0
  • 我其实不喜欢下雪,我喜欢不下雪的冬天。 今天办公室的空凋不给力,开到30摄氏度还感觉到冷。突然很向往同学口中北方的...
    请叫我焰火阅读 634评论 1赞 3

友情链接更多精彩内容