Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect the operating system using GWT?

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.

like image 325
Lipis Avatar asked Dec 07 '10 00:12

Lipis


1 Answers

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".

like image 131
Chris Lercher Avatar answered Oct 23 '22 08:10

Chris Lercher