Common code for client information such as browser type and operating system version in JavaScript

Source: Internet
Author: User

/*** @author Hechen*/var GS = {/** get screen width **/screenwidth:function () {return window.screen.width;  },/*** get screen height **/screenheight:function () {return window.screen.height;    },/** obtains the browser ***/browse:function () {var browser = {};    var useragent = Navigator.userAgent.toLowerCase ();    var s; (s = Useragent.match (/msie ([\d.] +)/)) ? browser.ie = S[1]: (s = Useragent.match (/firefox\/([\d.] +)/)) ? Browser.firefox = S[1]: (s = Useragent.match (/chrome\/([\d.] +)/)) ? Browser.chrome = S[1]: (s = Useragent.match (/opera. ( [\d.] +)/)) ? Browser.opera = S[1]: (s = Useragent.match (/version\/([\d.] +). *safari/))?    Browser.safari = S[1]: 0;    var version = "";    if (browser.ie) {version = ' ie ' + browser.ie;      } else {if (browser.firefox) {version = ' Firefox ' + Browser.firefox;        } else {if (browser.chrome) {version = ' chrome ' + browser.chrome; } else {if (Browser.opera) {version = ' Opera ' + Browser.opera;            } else {if (Browser.safari) {version = ' safari ' + Browser.safari;            } else {version = ' unknown browser ';  }}}}} return version;    },/** obtains operating system ***/Clientos:function () {var suseragent = navigator.useragent; var Iswin = (Navigator.platform = = "Win32") | |    (Navigator.platform = = "Windows"); var Ismac = (Navigator.platform = = "mac68k") | | (Navigator.platform = = "MacPPC") | | (Navigator.platform = = "Macintosh") | |    (Navigator.platform = = "Macintel");    if (ISMAC) return "Mac";    var Isunix = (Navigator.platform = = "X11") &&!iswin &&!ismac;    if (Isunix) return "Unix";    var islinux = (String (navigator.platform). IndexOf ("Linux") >-1);    if (islinux) return "Linux"; if (Iswin) {var iswin2k = suseragent.indexof ("Windows NT 5.0") >-1 | | suseragent.indexof ("Windows $") >-1      ;      if (iswin2k)  return "Win2000"; var iswinxp = Suseragent.indexof ("Windows NT 5.1") >-1 | |      Suseragent.indexof ("Windows XP") >-1;      if (ISWINXP) return "WinXP"; var isWin2003 = Suseragent.indexof ("Windows NT 5.2") >-1 | |      Suseragent.indexof ("Windows 2003") >-1;      if (isWin2003) return "Win2003"; var Iswinvista = Suseragent.indexof ("Windows NT 6.0") >-1 | |      Suseragent.indexof ("Windows Vista") >-1;      if (Iswinvista) return "WinVista"; var isWin7 = Suseragent.indexof ("Windows NT 6.1") >-1 | |      Suseragent.indexof ("Windows 7") >-1;    if (isWin7) return "Win7";  } return "Other";    },/**** obtains the client id****/clientid:function (name) {var cookies = Document.cookie.split (";");    var value = "";      for (var i = 0; i < cookies.length; i++) {var temp = cookies[i].split ("="); var tempvalue = temp[0].replace (/(^\s*) | (      \s*$)/g, "");        if (Tempvalue = = name) {value = Unescape (temp[1]); Break;  }} return value;    },/**** gets the product id****/searchgid:function () {var url = window.location.href;    var value = ""; if (url! = undefined && URL! = "") {Url.replace (/-\d+-/, function (A, B, c) {if (A! = undefined &amp        ;& A! = "" && a.length > 2) {value = a.substring (1, a.length-1);    }      });  } return value;    },/**** obtains the station search keyword ****/searchkey:function () {var url = window.location.href;    var value = ""; if (url! = undefined && URL! = "") {Url.replace (/[=].*/, function (A, B, c) {if (A! = undefined &amp        ;& A! = "" && a.length > 1) {value = a.substring (1);    }      });  } return value;    },/** gets the product category search number **/searchcategory:function () {var url = window.location.href;    var value = ""; if (url! = undefined && URL! = "") {Url.replace (/-\d+/, function (A, B, c) {if (A! = undefined & & A! = "" && A.lenGth > 1) {value = a.substring (1);    }      });  } return value;    },/**** outside the station search Google Baidu *****/searchsite:function (type) {var referrer = Document.referrer; if (referrer! = undefined && referrer! = ") {if (" google "= = type) {url.replace (New RegExp (?: ^| /?| &) q= ([^&]*) (?: &|$) "), function (A, B, c) {if (this._ch! = undefined && A! = undefined && Amp            A.length > 0) {a = A.substring (A.indexof ("=") + 1, a.length-1);          return A;      }        }); } else if ("baidu" = = Type) {url.replace (New RegExp (?: ^| /?| &) wd= ([^&]*) (?: &|$) "), function (A, B, c) {if (this._ch! = undefined && A! = undefined &            & a.length > 0) {a = A.substring (A.indexof ("=") + 1, a.length-1);          return A;      }        }); } else if ("sogou" = = Type) {url.replace (New RegExp (?: ^| /?| &) query= ([^&]*) (?: &|$) "), function (A, B, c) {if (this._ch! = undefined && A! = undefined && a.length > 0) {            A = a.substring (A.indexof ("=") + 1, a.length-1);          return A;      }        }); } else if ("bing" = = type) {url.replace (New RegExp (?: ^| /?| &) q= ([^&]*) (?: &|$) "), function (A, B, c) {if (this._ch! = undefined && A! = undefined && Amp            A.length > 0) {a = A.substring (A.indexof ("=") + 1, a.length-1);          return A;      }        });  }} return ""; },/****** inserts the value into the array *********/pushvalue:function (key, value) {if (this._ch! = undefined) {This._ch[key] = val    Ue    }},/*** custom parameter **/param:function (value) {if (this._ch! = undefined) {this._ch["_ps"] = value; }},/****** submits data to background **********/postdata:function () {$.ajax ({url: "HTTP://LOCALHOST:28482/AJAX/STATACTIONS.A    spx?t= "+ math.random (), type:" Post ", Data:this._ch,  Success:function (data) {}});    },/*** initializes **/init:function () {if (this._ch! = undefined) {this._ch = undefined;    } this._ch = {};    if (this._reg! = undefined) {this._reg = undefined;    }//Initialize regular expression match URL This._reg = new Array ();    This._reg[0] = "http://www.google.com.hk (. *)";    THIS._REG[1] = "http://www.baidu.com (. *)";    THIS._REG[2] = "http://www.sogou.com (. *)";     THIS._REG[3] = "http://cn.bing.com (. *)";    Parse URL parameter var hosturl = window.location.href; if (hosturl! = undefined && Hosturl! = "") {if ((new RegExp (THIS._REG[4))). Test (Hosturl)) {this._ch[ "_gid"] = this.      Searchgid ();        } else if (new RegExp (This._reg[7])). Test (Hosturl)) {} else if ((New RegExp (THIS._REG[5))). Test (Hosturl)) { this._ch["_cid"] = this.      Searchcategory (); } else if ((New RegExp (This._reg[6])). Test (Hosturl)) {this._ch["_key"] = this.      Searchkey ();    } this._ch["_tu"] = Hosturl; } var referrer =Document.referrer; if (referrer! = undefined && referrer! = "") {if ((new RegExp (this._reg[0))). Test (referrer)) {This._ ch["_key"] = this.      SearchSite ("Google"); } else if ((New RegExp (This._reg[1])). Test (referrer)) {this._ch["_key"] = this.      SearchSite ("Baidu"); } else if ((New RegExp (This._reg[2])). Test (referrer)) {this._ch["_key"] = this.      SearchSite ("Sogou"); } else if ((New RegExp (This._reg[3])). Test (referrer)) {this._ch["_key"] = this.      SearchSite ("Bing");    } this._ch["_su"] = referrer; }//Get client-related information this._ch["_SW"] = this.    ScreenWidth (); this._ch["_sh"] = this.    ScreenHeight (); this._ch["_BW"] = this.    Browse (); this._ch["_cs"] = this.    Clientos (); this._ch["_mid"] = this.    ClientID ("From_channelid"); this._ch["_ctid"] = this.   ClientID ("Clientkey"); }, _ch:undefined, _reg:undefined

Native JavaScript determines operating system version function Detectos () {var suseragent = navigator.useragent; var Iswin = (Navigator.platform = = "Win32") | |    (Navigator.platform = = "Windows"); var Ismac = (Navigator.platform = = "mac68k") | | (Navigator.platform = = "MacPPC") | | (Navigator.platform = = "Macintosh") | |    (Navigator.platform = = "Macintel");    if (ISMAC) return "Mac";    var Isunix = (Navigator.platform = = "X11") &&!iswin &&!ismac;    if (Isunix) return "Unix";    var islinux = (String (navigator.platform). IndexOf ("Linux") >-1);    if (islinux) return "Linux"; if (Iswin) {var iswin2k = suseragent.indexof ("Windows NT 5.0") >-1 | | suseragent.indexof ("Windows $") >        -1;        if (iswin2k) return "Win2000"; var iswinxp = Suseragent.indexof ("Windows NT 5.1") >-1 | |        Suseragent.indexof ("Windows XP") >-1;        if (ISWINXP) return "WinXP"; var isWin2003 = Suseragent.indexof ("Windows NT 5.2") >-1 | | Suseragent.indexof ("Windows 2003");        -1;        if (isWin2003) return "Win2003"; var Iswinvista = Suseragent.indexof ("Windows NT 6.0") >-1 | |        Suseragent.indexof ("Windows Vista") >-1;        if (Iswinvista) return "WinVista"; var isWin7 = Suseragent.indexof ("Windows NT 6.1") >-1 | |        Suseragent.indexof ("Windows 7") >-1;    if (isWin7) return "Win7"; } return "other";} Document.writeln ("Your operating system is:" + detectos ());

  

Common code for client information such as browser type and operating system version in JavaScript

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.