zoukankan      html  css  js  c++  java
  • 自己在做落地页过程中遇到的需求(禁止浏览器返回等)

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

    一、禁止浏览器返回

    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不同显示的图片不同
  • 相关阅读:
    juicer 语法
    mvc 理解
    php 之 trait
    阿里P8面试官:如何设计一个扛住千万级并发的架构?
    建模
    镜像推送时出现 server gave HTTP response to HTTPS client 问题的解决方法
    git在线练习网站
    ubuntu 20.04 LTS 更换阿里云源
    Proxmox VE(Proxmox Virtual Environment)制作优盘(U盘)启动盘的教程说明方法
    KubeSphere部署Nacos集群
  • 原文地址:https://www.cnblogs.com/yuanyanbk/p/11611978.html
Copyright © 2011-2022 走看看