0

I have a component in my website which used to show a download link, I want to remove this component whenever client visits my website using android web view.

Expected to have a function in js that determines this but couldn't find any

1 Answers1

0

You can try using the navigator.userAgent property to determine whether the client is using android web view.

function checkForWebView() {
  const userAgent = navigator.userAgent;
  
  if (userAgent.includes('Android')) {
    // The client is using an Android device.
    // Check if the user agent string contains the name of a known Android web view.
    if (userAgent.includes('Chrome') || userAgent.includes('Firefox') || userAgent.includes('SamsungBrowser')) {
      // The client is using a web view.
      return true;
    } else {
      // The client is not using a web view.
      return false;
    }
  } else {
    // The client is not using an Android device.
    return false;
  }
}
raykay
  • 46
  • 1
  • Thanks for response in advance, the code you mentioned includes chrome or any other browsers in android too, i don't want to remove component when client visits using a mobile browser but i want to do that if and only if its on mobile and on webview – Ayoub Rezaei Dec 03 '22 at 13:38
  • You can check out this thread, there may be something closer to what you are looking for - https://stackoverflow.com/questions/37591279/detect-if-user-is-using-webview-for-android-ios-or-a-regular-browser – raykay Dec 03 '22 at 14:45