(solved) identify user tool type

Monkey Targets Forums/HTML5/(solved) identify user tool type

golomp(Posted 2015) [#1]
I would like to identify with what tool a user consult my html app.

For example, with a PC, a user can type directly on keyboard.
For a smartphone, you need to enable keyboard to show the keyboard.

Ok i could enabling keyboard by default but my problem is : i am in a special loop
that can be controlled by user to scan keyboard and i must close the keyboard when it's finished.
So if a smartphone user wach the keyboard open and close any time
it's going to be uggly.

So, how can i identify if the user have a PC or if he use a smartphone ?


ziggy(Posted 2015) [#2]
I think getting the UserAgent can be handy:
Import dom
Extern
	Global navigator:Navigator
Public
Function Main()
	Print navigator.userAgent
End

This tells you some useful information both about browser and platform:
In my PC it was Mozilla/5.0 (Windows NT 6.1; rv:34.0) Gecko/20100101 Firefox/34.0


ImmutableOctet(SKNG)(Posted 2015) [#3]
Ziggy, I think you're complicating things.

You don't need your own external bindings, 'dom' already handles this for you:
' Obviously, you don't have to print it, but you get the idea; just a normal 'String'.
Print(window.navigator.userAgent)


That's it, 'window' is provided by 'dom', and it has the 'navigator' object inside of it. From there, just check against the user-agent.

External bindings are a good idea if you have an existing JavaScript routine you want to use. For example, if you want to use JQuery or something similar. I suggest searching around for the best methods for detecting mobile user-agents. This is also something that's commonly done on the backend, not the front-end with JavaScript/Monkey. But in the case of a game, I can see why you'd want to use a front-end check.

There's a number of StackOverflow posts you could look at. You could either use external bindings for JavaScript, or you could take advice about common user-agents and keep it as purely Monkey. Google and especially StackOverflow are every developer's friends.

Might I add that Monkey's DOM module is awesome, and if I used HTML5 more often, it would be a huge time saver.


golomp(Posted 2015) [#4]
Thank you alot !