简体   繁体   中英

possible to detect webapp or mobile browser in javascript

I am working with web application (iOS/Android)

Basically, My application looks like

  • Basically it is just webpage
  • Application wrapped it with WebView
  • So technically, user can access the page with mobile browser(like Safari, Chrome, etc even PC Web browser) and Mobile Application

what I trying to do is detecting request from user is form Mobile Application or mobile browser.(with javascript)

Is it even possible? If yes, recommend the method(I prefer native javascript since project is commercial)

Thanks.

PS I do not need device detect with navigator.userAgent , purpose of this job is detecting mobile browser or mobile app, not which device user uses.

You can add a custom user agent string for your application webview so that you can distinguish a webview from js For android you can use

myWebView.getSettings().setUserAgentString(<your custom user agent string>);

It is better to append extra string to the actual useragent string

myWebView.getSettings.getSettings().setUserAgentString(myWebView.getSettings().getUserAgentString() + <your custom user agent string>);

You can check whether the user agent string contains the custom extra string from JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM