JS技巧

一 判断移动终端类型

1. 判断是否是IE浏览系统

 isIE: function() {
   return (/msie/i).test(navigator.userAgent);
}

 

2. 判断是否是Android浏览系统

isAndroid: function() {
        var isAndroid = false, androidVersion;

        if(navigator.userAgent.indexOf("Android") >= 0 ) {
          androidVersion = parseFloat(navigator.userAgent.slice(navigator.userAgent.indexOf("Android")+8));
          if (androidVersion <= 2.4) {
              isAndroid = true;
          }
        }

        return isAndroid;
 }

 

3. 判断是否是Windows Phone 7浏览系统

 fontFaceCheck: function() {
        if (/Windows Phone OS 7/.test(navigator.userAgent)) {
          Modernizr.fontface = false;
          $("html").removeClass("fontface").addClass("no-fontface");
        }
}

 

二 URL Params

/*
 * URL Params - v1.0 - 8/28/2013
 * http://pastebin.com/yvfeK76y
 *
 * Include this in the document <head> for best results. It will create a global 
 * object "urlParams" that stores all querystring parameters in a URL.
 *
 * Uses/examples:
 * if ("foo" in urlParams) { ... }
 * var foo_value = urlParams["foo"];
 *
 */
var urlParams = {};

(function() {
    var e, a = /\+/g, r = /([^&=]+)=?([^&]*)/g, d = function(s) {
        return decodeURIComponent(s.replace(a, " "));
    }, q = window.location.search.substring(1);
    while (e = r.exec(q)) urlParams[d(e[1])] = d(e[2]);
})();

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。