detect operating system javascript - Web Development and Web Design Codes

Latest

Monday, February 19, 2018

detect operating system javascript

detect operating system JavaScript


Hi Friends in this JavaScript lesson we are going to learn how to detect operating system using JavaScript..
in this script we will detect Android OS,iOS,Windows OS,Linux OS,Mac OS
Just use the below script to detect operating system JavaScript..

index.html
<script>
function getOS() {
  var userAgent = window.navigator.userAgent,
      platform = window.navigator.platform,
      macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
      windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
      iosPlatforms = ['iPhone', 'iPad', 'iPod'],
      os = null;

  if (macosPlatforms.indexOf(platform) !== -1) {
    os = 'Mac OS';
  } else if (iosPlatforms.indexOf(platform) !== -1) {
    os = 'iOS';
  } else if (windowsPlatforms.indexOf(platform) !== -1) {
    os = 'Windows';
  } else if (/Android/.test(userAgent)) {
    os = 'Android';
  } else if (!os && /Linux/.test(platform)) {
    os = 'Linux';
  }

  return os;
}
</script>
<h3>Detect Operating System in JavaScript</h3>
<h3 style="color:green">Your Operating System is:<font color="red"><script>document.write(getOS())</script></font></h3> </h3>

That's it how to detect operating system using JavaScript..Keep visiting for more Codes..Thank You..

No comments:

Post a Comment

Thank You for Your Comment

Note: Only a member of this blog may post a comment.