• js监控微信浏览器的自带的返回事件(延迟解决微信返回立即执行popstate事件)


    /**
    * 浏览器回退事件监听
    */
    var listenerBackHandler = {
    param: {
        isRun: false, //防止微信返回立即执行popstate事件
    },
    listenerBack: function () {
        var state = {
            title: "title",
            url: "#"
        };
    window.history.pushState(state, "title", "#");
    
    window.addEventListener("popstate", function (e) {
    if (listenerBackHandler.param.isRun) {
        window.location.href = "Home/Index"; //返回到主页
    }
    }
    }, false);
    },
    //初始化返回事件
    initBack: function () {
    window.addEventListener('pageshow', function () {
        listenerBackHandler.param.isRun = false;
        setTimeout(function () { listenerBackHandler.param.isRun = true; }, 1000);         
        //延迟1秒 防止微信返回立即执行popstate事件
        listenerBackHandler.listenerBack();
    });
    }
    }    
    A journey of a thousand miles begins with a single step!
  • 相关阅读:
    install git on ubuntu
    deploy uwsgi with niginx on ubuntu
    ubuntu下部署solr
    solr relevent project
    20100722
    [Programming Visual C++]Ex05cCScrollView Revisited
    iter_test
    交友类节目
    install scrapy on windows
    20100703
  • 原文地址:https://www.cnblogs.com/qingfengweb/p/7552638.html
Copyright © 2020-2023  润新知