我如何使用GWT检测操作系统? [英] How can I detect the operating system using GWT?
本文介绍了我如何使用GWT检测操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
您可以使用:
import com.google.gwt.user.client.Window.Navigator;
...
String platform = Navigator.getPlatform();
这会返回一个String(与JavaScript的 navigator.platform
)。然后,您可以选择类似于此脚本的操作系统:它只是检查子字符串 Win/Mac/iPhone/Linux。
Basically what I want to know is to find out if my GWT application is running on a MacOS or any other operating system, to setup the shortcuts properly using cmd on a MacOS and ctrl everywhere else.
解决方案
You can use:
import com.google.gwt.user.client.Window.Navigator;
...
String platform = Navigator.getPlatform();
This returns a String (the same as JavaScript's navigator.platform
). You can then decide on the OS similar to this script: It simply checks for the substring "Win"/"Mac"/"iPhone"/"Linux".
这篇关于我如何使用GWT检测操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文