0

I want the JavaScript code for checking whether a website is open in webview (in application webview) or mobile Browser (like google chrome, uc browser).

I referred to these links: But it's not working for me ..

Detect inside Android Browser or WebView

Jaydeep Joshi
  • 53
  • 1
  • 2
  • 11
  • Possible duplicate of [detect ipad/iphone webview via javascript](http://stackoverflow.com/questions/4460205/detect-ipad-iphone-webview-via-javascript) – Jignesh Ansodariya Oct 05 '16 at 13:23
  • From Lollipop, android is providing a way to distinguish between WebView and browser with UserAgent property, you can check from "wv" value in UserAgent if it is WebView. For more go through [this link](https://developer.chrome.com/multidevice/user-agent) – Hardik Uchdadiya Jan 06 '17 at 04:31

1 Answers1

0

Activity -> onCreate

this.webView.getSettings().setUserAgentString(
    this.webView.getSettings().getUserAgentString() 
    + " "
    + getString(R.string.user_agent_suffix)
);

Res -> Values -> strings.xml

<string name="user_agent_suffix">AppName/1.0</string>

Javascript

function() isNativeApp {
    return /AppName\/[0-9\.]+$/.test(navigator.userAgent);
}

copied from here

Community
  • 1
  • 1
Ankit Aggarwal
  • 2,941
  • 2
  • 17
  • 26