JS detect browser version, core, whether to move the end of the sample _ basic knowledge

Source: Internet
Author: User

Detects browser versions, cores, systems, and whether to move the end

Copy Code code as follows:

/**
* Check Browser version
* @authors K
* @date 2014-04-11 14:48:39
* @version 1
*/

/**
* Detect browser info with navigator useragent
* @return Object Browser Info
*/

var browser = (function () {
  var useragent = navigator.useragent,
  UA = Useragent.tolowercase (),
  Browserlist = {
    msie:/(?: Msie\s|trident.*rv:) ([\w.] +/I,
    Firefox:/firefox\/([\w.] +/I,
    Chrome:/chrome\/([\w.] +/I,
    safari:/version\/([\w.] +). *safari/i,
    Opera:/(?: O pr\/| opera.+version\/) ([\w.] +)/I
 },
  kernels = {
    msie:/(compatible;\smsie\s| trident\/) [\w.] +/i,
    Camino:/camino/i,
    khtml:/khtml/i,
    Presto:/ Presto\/[\w.] +/i,
    Gecko:/gecko\/[\w.] +/i,
    WebKit:/applewebkit\/[\w.] +/i
 },
  browser = {
    kernel: ' Unknow ',
    version: ' Unknow '
 }

detecting browsers
for (var i in browserlist) {
var matchs = Ua.match (Browserlist[i]);
Browser[i] = matchs? True:false;
if (matchs) {
Browser.version = matchs[1];
}
}

Detection engine
for (var i in kernels) {
var matchs = Ua.match (Kernels[i]);
if (matchs) {
Browser.kernel = Matchs[0];
}
}

System
var os = Ua.match (/(windows\snt\s| mac\sos\sx\s| android\s|ipad.*\sos\s|iphone\sos\s) ([\d._-]+)/I);
Browser.os = Os!==null? Os[0]: false;

Whether to move the end
Browser.mobile = Ua.match (/mobile/i)!==null? True:false;

return browser;
}());

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.