码迷,mamicode.com
首页 > Web开发 > 详细

JS技巧

时间:2015-03-16 14:25:41      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

一 判断移动终端类型

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]);
})();

 

JS技巧

标签:

原文地址:http://www.cnblogs.com/wangshuo1/p/4341561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!