• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Identifying Chrome OS

A

arfeigenbaum

Guest
Hello,

I'm working on an HTML5 game that I'd like to show on-screen buttons for mobile devices and hide them for desktops. This is working fine using os_type, except for on chromebooks which run chrome OS. On Chromebook, I'm seeing the on-screen buttons, I believe because it is counting it as android OS.

Does anyone know a solution to this problem? Any advice would be appreciated!

Thanks,
Alex
 

BLang

Member
Maybe give an additional setting in the options menu that allows players on mobile devices to turn off the on-screen buttons? It's not a real 100% solution, but some people might even appreciate being able to make the buttons invisible as they get comfortable with the control scheme on their mobiles.
 

FrostyCat

Redemption Seeker
You can shim the answer from this StackOverflow post in an extension.

Create an extension, then create a JS file in it with the following code:
Code:
function is_chrome_os() {
  if (/\bCrOS\b/.test(navigator.userAgent)) {
    return 1;
  } else {
    return 0;
  }
}
Then create a function under the JS file named is_chrome_os with 0 arguments and an external name of is_chrome_os. Now you can call is_chrome_os() from within your code to check for Chrome OS.

PS: I strongly recommend that you get a handle on at least basic JS to save yourself from messes like this. It happens way more often than what most people around here give credit for, especially in commercial development. Same with Java on Android and Objective C on iOS.
 

True Valhalla

Full-Time Developer
GMC Elder
You can also explicitly check os_type for Windows, Mac, Linux for a (rough) quick fix. If none of those appear the user is most likely on mobile.
 
Top