通过Java或JavaScript进行操作系统检测 [英] Operating System Detection by Java or JavaScript

查看:62
本文介绍了通过Java或JavaScript进行操作系统检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测操作系统名称&Java版本.我可以通过

I need to detect OS name & version in Java. That I can do by

String os_name = System.getProperty("os.name", "");
String os_version = System.getProperty("os.version", "");

,但是问题在于这不可靠.有时它返回错误的信息,并且我无法检测到所有操作系统,除了最流行的Windows,MacOS,Linux等,在64位操作系统的情况下,甚至会提供错误的信息.我需要检测具有任何规格的任何操作系统.我无法为此找到合适的解决方案.

but the problem is that this is not reliable. Sometimes it returns incorrect information, and I can't detect all operating systems, except the most popular Windows, MacOS, Linux etc, and this even provides wrong information in the case of 64 bit operating systems. I need to detect any OS with any kind of specification. I am unable to find the right solution for this.

也许我可以使用JavaScript做到这一点?如果用Java无法实现,请告诉我如何使用JavaScript.

Maybe I can do this with JavaScript? If it's impossible in Java then please tell me how to do it with JavaScript.

任何意见或建议都值得赞赏.

Any input or suggestions highly appreciated.

谢谢.

最诚挚的问候,

** Nilanjan Chakraborty

**Nilanjan Chakraborty

推荐答案

在Java中,在猜测操作系统时存在一些常见的错误:

In Java there are some common bugs while guessing the operating system:

http://bugs.sun.com/view_bug.do?bug_id=6819886

也许在Java的较新版本中,它们已解决.

Maybe in newer versions of Java, they are solved.

在Javascript中,您可以使用navigator.appVersion:

In Javascript you can use navigator.appVersion:

// This script sets OSName variable as follows:
// "Windows"    for all versions of Windows
// "MacOS"      for all versions of Macintosh OS
// "Linux"      for all versions of Linux
// "UNIX"       for all other UNIX flavors 
// "Unknown OS" indicates failure to detect the OS

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

document.write('Your OS: '+OSName);

这篇关于通过Java或JavaScript进行操作系统检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆