android - How to know if I'm runnning my website in th mobile or as a mobile app? -


i'll create webapp of web. heard of lot of services make easy:

i want create mobile apps using tools wrap html5/css/js deployable app-store type app, want use source html5/css/js conventional website (appmakr, appsbuilder, appgeyser...)

there way able tell js whether running in browser or mobile app?

any tip, or advice appreciated, , if need more info, let me know , i'll edit post.

to tell difference between http request coming mobile application or mobile browswer can use user agent. safari/ios respective user agent examples follows:

mobile browswer:

mozilla/5.0 (ipad; u; cpu os 4_3_2 mac os x; en-us) applewebkit/533.17.9 (khtml, gecko) version/5.0.2 mobile/8h7 safari 

mobile app:

mozilla/5.0 (ipad; u; cpu os 4_3_2 mac os x; en-us) applewebkit/533.17.9 (khtml, gecko) mobile 

the check in case being mobile vs "version/5.0.2 mobile/8h7 safari" on end.

to make same check in android, can following:

function() isnativeapp {     return /appname\/[0-9\.]+$/.test(navigator.useragent); } 

on user agent, when attempting append content webview javascript enabled.

note checks specific user agents unadvisable version numbers evolving, example of logic/information can use. browser compatibility libraries jquery provide utilities intelligent "browswer" sniffing, should allow in safer manner logic above presents. overview of information you're looking for. way, checking specific user agents bad idea... okay point made.

references:

detect inside android browser or webview

does uiwebview send same user-agent in request headers mobile safari?


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -