HTML5 Builds Device Info Check

Hi! Is there a way to check if user is using mobile or desktop when runnning HTML5 builds? Thank you!

Yes, put this in JS. It’s best, simplest method I’ve found.

	function isMobileDevice() {
		return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
	};

Then in Lua

if html5 then
  if html5.run("isMobileDevice()") then
    ... -- do whatever
  end
end

You can also just do

if html5.run("(typeof window.orientation !== 'undefined') || (navigator.userAgent.indexOf('IEMobile') !== -1);") then ... end
8 Likes

We should probably provide some additional information in sys.get_sys_info(). There is user_agent but I’m not sure if that is useful or not.

3 Likes

Yes, detection between HTML5 browser and mobile devices browser is very useful. For mobile i need display onscreen controls same as in an android build.

2 Likes

Pkeod’s code seems to work fine for me, with one little caveat: html5.run always returns a string! So you need to check if the result is "true" or "false".

1 Like