HTML5 conditionals, for Mobile web

  • Hi. I'm trying to find out if there's a way to check whether the user is on a Desktop, or Mobile on HTML5, to add controls for Mobile users, playing an HTML5 game in a browser..

    #if mobile, only seems to work on native code.

  • Hi!

    You might find this useful

    Besides that, if you plan to add a custom compiler conditional, you can easily do so. In your project.xml file, you could add:

    <haxedef name="custom_platform"   />

    And then just check if that flag is set by doing

    #if custom_platform

  • administrators

    #if mobile, or any other haxedefs for that matter, can't help you here because they're compile-time. You'd need to check whether you're on a mobile browser or not at runtime, since you most likely want to support mobile and desktop platforms with the same HTML5 build.

    There should be plenty of resources around of how to do this in JS (see here for example). You can execute JavaScript code in Haxe via untyped:

  • Thanks a lot! This is what I needed to know.

Log in to reply