js常用方法封装

//获取cookie
// var user_id     = getCookie('ECS[user_id]');
function getCookie(c_name){
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
            { 
                c_start=c_start + c_name.length+1 
                c_end=document.cookie.indexOf(";",c_start)
                if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))
            } 
        }
    return "";
}

//获取get传参值
// var step= getUrlParam().step;
if(typeof(getUrlParam) != "function"){
    function getUrlParam(){
        var args = {};
        var match = null;
        var search = decodeURIComponent(location.search.substring(1));
        var reg = /(?:([^&]+)=([^&]+))/g;
        while((match = reg.exec(search))!==null){
            args[match[1]] = match[2];
        }
        return args;
    }
}

//判断浏览器
var browser={
    versions:function(){
        var u = navigator.userAgent, app = navigator.appVersion;
        return {
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
            weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
        };
    }()
}
if(browser.weixin){
    //wechat browser visit
}

//判断是否是微信浏览器访问
function is_weixin_browser() {
    // return true;
    var ua = navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true;
    } else {
        return false;
    }
}
if(is_weixin_browser()){
    //wechat browser visit
}

 

posted on 2018-03-16 09:43  爱吃柠檬不加糖  阅读(135)  评论(0编辑  收藏  举报

导航