How do I detect the browser from Elm?
Specifically I want to be able to tell if the web app is running on a tablet (Safari on iPad, etc.) or not.
How do I detect the browser from Elm?
Specifically I want to be able to tell if the web app is running on a tablet (Safari on iPad, etc.) or not.
You can use Html.programWithFlags
to pass information from Javascript to Elm on initialization.
Assuming you can infer browser from user agent, you could do something like this:
type alias Flags =
{ userAgent : String }
Your init
would look like this:
init : Flags -> ( Model, Cmd Msg )
init flags =
...
main =
programWithFlags { init = init, ... }
And from Javascript, you would pass the flags in like this:
var app = Elm.Main.fullscreen({
userAgent: navigator.userAgent
});
Side note: User agent may not be enough to fully detect browser. You can see this StackOverflow answer which provides more reliable detection. Either way, the end result is that you would send some kind of flag along to the Elm app on init.
You can use elm-vendor
package.
http://package.elm-lang.org/packages/coreytrampe/elm-vendor/latest