Determine the type of mobile device

Source: Internet
Author: User

Window. Xfun = {
"GetById": function getById (ID) {
return document.getElementById (ID);
},
"Geturlparam": function (name) {
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)"); Constructs a regular expression object that contains a target parameter
var r = decodeURI (Window.location.search). substr (1). Match (REG); Match target parameters
if (r! = null) {return unescape (r[2]);} return null;
},
"GetUrlParam2": function (name) {
var reg = new RegExp ("(^|&)" + name + "= ([^&]*) (&|$)"); Constructs a regular expression object that contains a target parameter
var r = decodeuricomponent (Window.location.search). substr (1). Match (REG); Match target parameters
if (r! = null) {return unescape (decodeURI (r[2]));} return null;
},
Versions:function () {
var u = navigator.useragent, app = Navigator.appversion;
return {//Mobile terminal browser version information
Ios:!! U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS x/),//ios terminal
Android:u.indexof (' Android ') >-1 | | U.indexof (' Linux ') >-1,//android terminal or UC Browser
Iphone:u.indexof (' iphone ') >-1,//whether for iphone or Qqhd browser
Ipad:u.indexof (' ipad ') >-1,//whether ipad
};
},
Getwindowsize:function () {
var size ={"width": 0, "height": 0};
if (window.innerwidth && window.innerheight)
{
Size.width= (window.innerwidth);
Size.height= (Window.innerheight);
}else if (document.documentelement && document.documentElement.clientHeight && Document.documentElement.clientWidth) {
Size.width= (Document.documentElement.clientWidth);
Size.height= (Document.documentElement.clientHeight);
}
return size;
},
Is_weixn:function () {
var ua = Navigator.userAgent.toLowerCase ();
if (Ua.match (/micromessenger/i) = = "Micromessenger") {
return true;
} else {
return false;
}
}
};
/*
* $Id: base64.js,v 2.15 2014/04/05 12:58:57 Dankogai Exp Dankogai $
*
* Licensed under the BSD 3-clause License.
* Http://opensource.org/licenses/BSD-3-Clause
*
* References:
* Http://en.wikipedia.org/wiki/Base64
*/

(function (Global) {
' Use strict ';
Existing version for Noconflict ()
var _base64 = Global. Base64;
var version = "2.1.9";
If node. js, we use Buffer
var buffer;
if (typeof module!== ' undefined ' && module.exports) {
try {
Buffer = require (' buffer '). Buffer;
} catch (Err) {}
}
Constants
var b64chars
= ' abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/';
var b64tab = function (bin) {
var t = {};
for (var i = 0, L = bin.length; i < L; i++) T[bin.charat (i)] = i;
return t;
} (B64chars);
var fromcharcode = String.fromCharCode;
Encoder Stuff
var Cb_utob = function (c) {
if (C.length < 2) {
var cc = c.charcodeat (0);
return cc < 0x80? C
: CC < 0x800? (fromCharCode (0xc0 | (CC >>> 6))
+ fromCharCode (0x80 | (CC & 0x3f)))
: (fromCharCode (0xe0 | ((cc >>>) & 0x0f))
+ fromCharCode (0x80 | ((CC >>> 6) & 0x3f))
+ fromCharCode (0x80 | (CC & 0x3f)));
} else {
var cc = 0x10000
+ (c.charcodeat (0)-0xD800) * 0x400
+ (C.charcodeat (1)-0xdc00);
Return (fromCharCode (0xf0 | ((cc >>>) & 0x07))
+ fromCharCode (0x80 | ((cc >>>) & 0x3f))
+ fromCharCode (0x80 | ((CC >>> 6) & 0x3f))
+ fromCharCode (0x80 | (CC & 0x3f)));
}
};
var Re_utob =/[\ud800-\udbff][\udc00-\udffff]| [^\x00-\x7f]/g;
var Utob = function (u) {
Return U.replace (Re_utob, Cb_utob);
};
var cb_encode = function (CCC) {
var Padlen = [0, 2, 1][ccc.length% 3],
Ord = ccc.charcodeat (0) << 16
| ((Ccc.length > 1? ccc.charcodeat (1): 0) << 8)
| ((Ccc.length > 2 ccc.charcodeat (2): 0)),
chars = [
B64chars.charat (Ord >>> 18),
B64chars.charat ((Ord >>>) & 63),
Padlen >= 2? ' = ': B64chars.charat ((Ord >>> 6) & 63),
Padlen >= 1? ' = ': B64chars.charat (Ord & 63)
];
Return Chars.join (");
};
var Btoa = Global.btoa? function (b) {
return Global.btoa (b);
}: Function (b) {
Return B.replace (/[\s\s]{1,3}/g, Cb_encode);
};
var _encode = buffer? function (U) {
return (U.constructor = = = Buffer.constructor? u:new buffer (U))
. toString (' base64 ')
}
: function (U) {return Btoa (Utob (U))}
;
var encode = function (U, urisafe) {
Return!urisafe
? _encode (String (U))
: _encode (String (U)). replace (/[+\/]/g, function (M0) {
return M0 = = ' + '? ‘-‘ : ‘_‘;
}). replace (/=/g, ");
};
var encodeURI = function (u) {return encode (U, True)};
Decoder stuff
var Re_btou = new RegExp ([
' [\XC0-\XDF][\X80-\XBF] ',
' [\xe0-\xef][\x80-\xbf]{2} ',
' [\xf0-\xf7][\x80-\xbf]{3} '
].join (' | '), ' G ');
var Cb_btou = function (CCCC) {
Switch (cccc.length) {
Case 4:
var cp = ((0x07 & cccc.charcodeat (0)) << 18)
| ((0x3f & Cccc.charcodeat (1)) << 12)
| ((0x3f & Cccc.charcodeat (2)) << 6)
| (0x3f & Cccc.charcodeat (3)),
offset = cp-0x10000;
Return (fromCharCode (offset >>>) + 0xD800)
+ fromCharCode ((offset & 0x3ff) + 0xdc00);
Case 3:
Return fromCharCode (
((0x0f & cccc.charcodeat (0)) << 12)
| ((0x3f & Cccc.charcodeat (1)) << 6)
| (0x3f & Cccc.charcodeat (2))
);
Default
Return fromCharCode (
((0x1f & cccc.charcodeat (0)) << 6)
| (0x3f & Cccc.charcodeat (1))
);
}
};
var Btou = function (b) {
Return B.replace (Re_btou, Cb_btou);
};
var cb_decode = function (CCCC) {
var len = cccc.length,
Padlen = len% 4,
n = (len > 0? b64tab[cccc.charat (0)] << 18:0)
| (Len > 1? B64tab[cccc.charat (1)] << 12:0)
| (Len > 2? B64tab[cccc.charat (2)] << 6:0)
| (Len > 3? B64tab[cccc.charat (3)]: 0),
chars = [
fromCharCode (n >>> 16),
fromCharCode ((n >>> 8) & 0xff),
fromCharCode (N & 0xff)
];
Chars.length-= [0, 0, 2, 1][padlen];
Return Chars.join (");
};
var Atob = Global.atob? function (a) {
Return Global.atob (a);
}: Function (a) {
Return A.replace (/[\s\s]{1,4}/g, Cb_decode);
};
var _decode = buffer? function (a) {
return (A.constructor = = = Buffer.constructor
? A:new buffer (A, ' base64 '). toString ();
}
: function (a) {return Btou (Atob (a))};
var decode = function (a) {
Return _decode (
String (a). Replace (/[-_]/g, function (M0) {return M0 = = '-'? ' + ': '/'})
. replace (/[^a-za-z0-9\+\/]/g, ")
);
};
var noconflict = function () {
var Base64 = Global. Base64;
Global. Base64 = _base64;
return Base64;
};
Export Base64
Global. Base64 = {
Version:version,
Atob:atob,
Btoa:btoa,
Frombase64:decode,
Tobase64:encode,
Utob:utob,
Encode:encode,
Encodeuri:encodeuri,
Btou:btou,
Decode:decode,
Noconflict:noconflict
};
If ES5 is available, make base64.extendstring () available
if (typeof object.defineproperty = = = ' function ') {
var noenum = function (v) {
return {value:v,enumerable:false,writable:true,configurable:true};
};
Global. base64.extendstring = function () {
Object.defineproperty (
String.prototype, ' FromBase64 ', noenum (function () {
Return decode (This)
}));
Object.defineproperty (
String.prototype, ' ToBase64 ', noenum (function (Urisafe) {
Return encode (this, urisafe)
}));
Object.defineproperty (
String.prototype, ' Tobase64uri ', noenum (function () {
Return encode (this, true)
}));
};
}
That ' s it!
if (global[' Meteor ']) {
Base64 = Global. Base64; For normal export in Meteor.js
}
}) (this);

Determine the type of mobile device

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.