How to detect my browser version and operating system using JavaScript?

后端 未结 10 944
天命终不由人
天命终不由人 2020-11-22 06:25

I have tried using the code below but it only display results in Chrome and Mozilla not working in IE6.

10条回答
  •  不思量自难忘°
    2020-11-22 07:27

    To detect operating system using JavaScript it is better to use navigator.userAgent instead of navigator.appVersion

    {
      var OSName = "Unknown OS";
      if (navigator.userAgent.indexOf("Win") != -1) OSName = "Windows";
      if (navigator.userAgent.indexOf("Mac") != -1) OSName = "Macintosh";
      if (navigator.userAgent.indexOf("Linux") != -1) OSName = "Linux";
      if (navigator.userAgent.indexOf("Android") != -1) OSName = "Android";
      if (navigator.userAgent.indexOf("like Mac") != -1) OSName = "iOS";
      console.log('Your OS: ' + OSName);
    }

提交回复
热议问题