JavaScript gets native operating system type methods _javascript tips

Source: Internet
Author: User
Tags win32

Needless to say, the following is a code example to introduce, I hope to be able to bring more or less to help friends.

Sample code:

function Getosinfo () {var _pf=navigator.platform; 
 var appver=navigator.useragent; 
  if (_pf== "Win32" | | | _pf = = "Windows") {if (appVer.indexOf ("WOW64") >-1) {_bit = "64-bit"; 
  else {_bit = "32 bits"; } if (appVer.indexOf ("Windows NT 6.0") >-1 | | | appver.indexof ("Windows Vista") >-1) {if (_bit== ' 64-bit ' | | | ap 
   Pver.indexof ("Windows Vista") >-1) {return ' Windows_vista ' +_bit; 
   else {return "Unknow1"; } else if (appVer.indexOf ("Windows NT 6.1") >-1 | | | appver.indexof ("Windows 7") >-1) {if (_bit== ' 32-bit ') || 
   appVer.indexOf ("Windows 7") >-1) {return ' windows_7 ' +_bit; 
   else {return "unknow"; 
    } else {try {var _winname = Array ('% ', ' XP ', ' 2003 '); 
    var _ntnum = Appver.match (/windows NT 5.\d/i). toString (); Return ' Windows_ ' + _winname[_ntnum.replace (/windows NT 5. ( 
   \d)/I, "$"]+ "" +_bit;
   catch (e) {return ' Windows '; } 
  }
 else if (_PF = "mac68k" | | | _pf = "MACPPC" | | _pf = "Macintosh") {return "Mac"; 
 else if (_PF = = "X11") {return "Unix"; 
 else if (String (_PF). IndexOf ("Linux") >-1) {return "Linux"; 
 else {return "unknow"; } 
}

The above code is very simple to achieve the JavaScript access to the native operating system types of methods, in a sample code to introduce JavaScript to obtain operating system version information

JavaScript gets the operating system version information

Sample code:

var suseragent = navigator.useragent;
var fappversion = parsefloat (navigator.appversion);
  Compare browser version size function compareversions (sversion1,sversion2) {var aVersion1 = Sversion1.split (".");
  var aVersion2 = Sversion2.split (".");
  if (aversion1.length>aversion2.length) {for (Var i=0;i<aversion1.length;i++) Aversion2.push ("0");
  }else if (aversion1.length<aversion2.length) {for (Var i=0;i<aversion2.length;i++) Aversion1.push ("0");
    for (Var i=0;i<aversion1.length;i++) {if (aversion1[i]<aversion2[i]) return-1;
  else if (Aversion1[i]>aversion2[i]) return 1;
return 0;
}//Detect if Opera browser var isopera = Suseragent.indexof ("opera") >-1;
var isMinOpera4 = IsMinOpera5 = IsMinOpera6 = IsMinOpera7 = Isminopera7_5 = false;
  if (Isopera) {var foperaversion;
  if (navigator.appname = = "Opera") {foperaversion = fappversion;
else {var reoperaversion = new RegExp ("Opera (http://www.cnblogs.com/eoiioe/admin/file://d+///d+)");    Reoperaversion.test (suseragent);
  Foperaversion = parsefloat (regexp["$");
  } ISMINOPERA4 = Foperaversion >= 4;
  IsMinOpera5 = foperaversion >= 5;
  IsMinOpera6 = foperaversion >= 6;
  IsMinOpera7 = foperaversion >= 7;
Isminopera7_5 = Foperaversion >= 7.5; //Detect if safari var iskhtml = suseragent.indexof ("khtml") >-1 | | Suseragent.indexof ("Konqueror") >-1 | |
Suseragent.indexof ("AppleWebKit") >-1;
var IsMinSafari1 = Isminsafari1_2 = false;
var isminkonq2_2 = isMinKonq3 = Isminkonq3_1 = Isminkonq3_2 = false;
  if (iskhtml) {Issafari = Suseragent.indexof ("AppleWebKit") >-1;
  Iskonq = Suseragent.indexof ("Konqueror") >-1; if (Issafari) {var reapplewebkit = new RegExp ("applewebkit\\/http://www.cnblogs.com/eoiioe/admin/file://d+ (/?:\
    \.\\d*) ");
    Reapplewebkit.test (suseragent);
    var fapplewebkitversion = parsefloat (regexp["$");
    IsMinSafari1 = fapplewebkitversion >= 85; Isminsafari1_2 = fapplewebkitversion >= 124; else if (Iskonq) {var rekonq = new RegExp ("konqueror\\/http://www.cnblogs.com/eoiioe/admin/file://d+" (/?:\ \.\\d+ (?: \
    \.\\d) ");
    Rekonq.test (suseragent);
    Isminkonq2_2 = CompareVersions (regexp["$"], "2.2") >= 0;
    ISMINKONQ3 = CompareVersions (regexp["$"], "3.0") >= 0;
    Isminkonq3_1 = CompareVersions (regexp["$"], "3.1") >= 0;
  Isminkonq3_2 = CompareVersions (regexp["$"], "3.2") >= 0; }//Detect ie var Isie = suseragent.indexof ("compatible") >-1 &&suseragent.indexof ("MSIE") >-1 &A
mp;&!isopera;
var isMinIE4 = isMinIE5 = Isminie5_5 = IsMinIE6 = IsMinIE7 = false;
  if (Isie) {var reie = new RegExp ("MSIE (http://www.cnblogs.com/eoiioe/admin/file://d+///d+);");
  Reie.test (suseragent);
  var fieversion = parsefloat (regexp["$");
  IsMinIE4 = Fieversion >=4;
  isMinIE5 = Fieversion >=5;
  Isminie5_5 = Fieversion >=5.5;
  IsMinIE6 = Fieversion >=6;
IsMinIE7 = Fieversion >=7; }//Detect firfox var ISFF = suseragent.IndexOf ("Firefox") >-1&&!isKHTML;
var isMinFF1 = isMinFF2 =isminff3 = false; if (ISFF) {var Reff = new RegExp ("firefox\\/" http://www.cnblogs.com/eoiioe/admin/file://d+///d+ (?: \
  \.\\d+\\.\\d+) ");
  Reff.test (suseragent);
  isMinFF1 = CompareVersions (regexp["$", "1.0") >=0;
  isMinFF2 = CompareVersions (regexp["$", "2.0") >=0;
IsMinFF3 = CompareVersions (regexp["$", "3.0") >=0;
//detect mozilla var Ismoz = Suseragent.indexof ("Gecko") >-1&&!isKHTML;
var isMinMoz1 = Isminmoz1_4 = Isminmoz1_5 = Isminmoz1_8 = false; if (Ismoz) {var remoz = new RegExp ("rv: (http://www.cnblogs.com/eoiioe/admin/file://d+///d+ (?: \
  \.\\d+) ");
  Remoz.test (suseragent);
  ISMINMOZ1 = CompareVersions (regexp["$", "1.0") >=0;
  Isminmoz1_4 = CompareVersions (regexp["$", "1.4") >=0;
  Isminmoz1_5 = CompareVersions (regexp["$", "1.5") >=0;
Isminmoz1_8 = CompareVersions (regexp["$", "1.8") >=0; } var isNS4 =!isie&&!isopera&&!ismoz&&!iskhtml && (Suseragent.indexof ("Mozilla") ==0) && (navigator.appname = "Netscape") && (Fappversion &
Gt;= 4.0 && fappversion <5.0);
var isMinNS4 = Isminns4_5 = Isminns4_7 =isminns4_8 = false;
  if (isNS4) {isMinNS4 = true;
  Ifminns4_5 = fappversion >= 4.5;
  ifminns4_7 = fappversion >= 4.7;
Ifminns4_8 = fappversion >= 4.8; //Detect operating system var Iswin = (Navigator.platform = = "Win32") | |
(Navigator.platform = = "Windows"); var Ismac = (Navigator.platform = = "mac68k") | | (Navigator.platform = = "MacPPC") | |
(Navigator.platform = = "Macintosh");
var Isunix = (Navigator.platform = = "X11" &&!iswin &&!ismac);
var IsWin95 = IsWin98 = isWinNT4 = Iswin2k = Iswinme = Iswinxp = Iswin2k3 = Isvista = false;
var ismac68k = ISMACPPC = false;
var Issunos = isMinSunOS4 = IsMinSunOS5 = Isminsunos5_5 = false; mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1. NET CLR 2.0.50727;. NET CLR 3.0.04506) if (iswin) {IsWin95 = Suseragent.indexof("Win95") >-1 | |
  Suseragent.indexof ("Windows)" >-1; IsWin98 = Suseragent.indexof ("Win98") >-1 | |
  Suseragent.indexof ("Windows)" >-1; Iswinme = Suseragent.indexof ("Win 9x 4.90") >-1 | |
  Suseragent.indexof ("Windows ME") >-1; Iswin2k = Suseragent.indexof ("Windows NT 5.0") >-1 | |
  Suseragent.indexof ("Windows") >-1; ISWINXP = Suseragent.indexof ("Windows NT 5.1") >-1 | |
  Suseragent.indexof ("Windows XP") >-1; ISWIN2K3 = Suseragent.indexof ("Windows NT 5.2") >-1 | |
  Suseragent.indexof ("Windows 2003") >-1; Detection Vista system may have bugs Isvista = Suseragent.indexof ("Windows NT 6.0") >-1 | |
  Suseragent.indexof ("Windows Vista") >-1; if (!iswin2k3&&!isvista) {isWinNT4 = Suseragent.indexof ("WinNT") >-1 | | suseragent.indexof ("Windo WS NT ") >-1 | | Suseragent.indexof ("WinNT4.0") >-1 | | (Suseragent.indexof ("Windows NT 4.0") >-1) && (!ISWINME&AMP;&AMP;!ISWIN2K&AMP;&AMP;!ISWINXP);
  } if (Ismac) {ismac68k = Suseragent.indexof ("mac_68000") >-1 | | suseragent.indexof ("68K") >-1; ISMACPPC = Suseragent.indexof ("Macpowerpc") >-1 | |
Suseragent.indexof ("PPC") >-1;
  } if (Isunix) {Issunos = Suseragent.indexof ("SunOS") >-1; if (Issunos) {var resunos = new RegExp ("SunOS" http://www.cnblogs.com/eoiioe/admin/file://d+///d+ (?: \
    \.\\d+) ");
    Resunos.test (suseragent);
    IsMinSunOS4 = CompareVersions (regexp["$"], "4.0") >= 0;
    IsMinSunOS5 = CompareVersions (regexp["$"], "5.0") >= 0;
  Isminsunos5_5 = CompareVersions (regexp["$"], "5.5") >= 0;
} document.write ("<br/>");
document.write ("IE browser:" + Isie);
document.write ("<br/>");
document.write ("Firfor browser:" + ISFF);
document.write ("<br/>");
document.write ("Windows Operating system:" + Iswin);
document.write ("<br/>");
document.write ("<br/>");
document.write ("Mozilla 1.5↑:" + isminmoz1_5);
document.write ("<br/>"); document.write ("Mozilla 1.8↑:" + Isminmoz1_8);
document.write ("<br/>");
document.write ("Firfox 1.0↑:" + isMinFF1);
document.write ("<br/>");
document.write ("Firfox 2.0↑:" + isMinFF2);
document.write ("<br/>");
document.write ("Firfox 3.0↑:" + isMinFF3);
document.write ("<br/>");
document.write ("IE 4.0↑:" + isMinIE4);
document.write ("<br/>");
document.write ("IE 5.0↑:" + isMinIE5);
document.write ("<br/>");
document.write ("IE 5.5↑:" + isminie5_5);
document.write ("<br/>");
document.write ("IE 6.0↑:" + isMinIE6);
document.write ("<br/>");
document.write ("IE 7.0↑:" + isMinIE7);
document.write ("<br/>");
document.write ("Windows:" + isWin95);
document.write ("<br/>");
document.write ("Windows:" + isWin98);
document.write ("<br/>");
document.write ("Windows ME:" + iswinme);
document.write ("<br/>");
document.write ("Windows NT:" + isWinNT4);
document.write ("<br/>");
document.write ("Windows:" + iswin2k);
document.write ("<br/>"); document.write ("WiNdows XP: "+ ISWINXP";
document.write ("<br/>");
document.write ("Windows 2003:" + iswin2k3);
document.write ("<br/>");
document.write ("Windows Vista:" + Isvista); document.write ("<br/>");

The code is simple to get the operating system version information of the native or non-native, and hopefully it will be a little more or less helpful to everyone.

Related Article

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.