Javascript getOS


SUBMITTED BY: Guest

DATE: June 6, 2013, 2:15 p.m.

FORMAT: JavaScript

SIZE: 949 Bytes

HITS: 1362

  1. <!DOCTYPE html>
  2. <html>
  3. <head><title></title>
  4. <script>
  5. function getOS() {
  6. // This script sets OSName variable as follows:
  7. // "Windows" for all versions of Windows
  8. // "MacOS" for all versions of Macintosh OS
  9. // "Linux" for all versions of Linux
  10. // "UNIX" for all other UNIX flavors
  11. // "Unknown OS" indicates failure to detect the OS
  12. var OSName = "Unknown OS";
  13. if (navigator.appVersion.indexOf("Win") != -1) OSName = "Windows";
  14. if (navigator.appVersion.indexOf("Mac") != -1) OSName = "MacOS";
  15. if (navigator.appVersion.indexOf("X11") != -1) OSName = "UNIX";
  16. if (navigator.appVersion.indexOf("Linux") != -1) OSName = "Linux";
  17. alert("Your OS is " + OSName);
  18. }
  19. </script>
  20. </head>
  21. <body onload="getOS();">
  22. </body>
  23. </html>

comments powered by Disqus