自己在做落地页过程中遇到的需求(禁止浏览器返回等)

以下都是自己在工作过程中让做的一些需求,不为啥,就做个笔记

一、禁止浏览器返回

stopBack: function () {
        var that = this,_num=0;
        if (window.history && window.history.pushState) {
            $(window).on('popstate', function() {
                _num++;
                if(Number(_num)<that.kfh||that.kfh==0){
                    window.history.pushState('forward', null, document.URL);
                    window.history.forward(1);
                    setTimeout(function () {
                        that.down();
                    }, 5000);
                } else {
                    window.history.go(-1);
                    _num=0;
                }
            });
            window.history.pushState('forward', null, document.URL);
            window.history.forward(1);
        }
    }
//进入页面调用stopBack方法即可

二、一些打开环境的判断

 //判断系统是ios还是安卓
    sysTemInfo: function () {
        var us = navigator.userAgent.toLowerCase();
        if ((us.indexOf('android') > -1 || us.indexOf('linux') > -1) || navigator.platform.toLowerCase().indexOf('linux') != -1) {
            return 'android';
        } else if (us.indexOf('iphone') > -1 || us.indexOf('ipad') > -1) {
            return 'ios';
        }else{
            return 'pc';
        }
    },

//判微信判断
     isWeChat: function () {
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == "micromessenger") {
            return true;
        } else {
            return false;
        }
    },
//微博判断
    isWeiBo:function(){
        var ua = navigator.userAgent.toLowerCase();
        if (ua.match(/WeiBo/i) == "weibo") {
            return true;
        } else {
            return false;
        }
    },

三、因为在微信中打开页面不能下载,引导去浏览器下载,所以就用了下面这个方法

weChatRes: function (n) {
        $('.wechat').length&&$('.wechat').remove();
        var html = '<div class="wechat"><img src="' + n + '" alt="点击右上角,然后选择浏览器打开!"/></div>';
        $('body').append(html);
    },
//这个传值n,是根据安卓或者ios不同显示的图片不同
原文地址:https://www.cnblogs.com/yuanyanbk/p/11611978.html