【问题标题】:How to check if client uses web view?如何检查客户端是否使用网络视图?
【发布时间】:2022-12-03 21:47:41
【问题描述】:

我的网站中有一个组件用于显示下载链接,每当客户端使用 android web 视图访问我的网站时,我想删除该组件。

期望在 js 中有一个函数来确定这个但找不到任何

【问题讨论】:

    标签: javascript jquery frontend


    【解决方案1】:

    您可以尝试使用 navigator.userAgent 属性来确定客户端是否正在使用 android web 视图。

    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;
      }
    }
    

    【讨论】:

    • 感谢您提前回复,您提到的代码也包括 chrome 或 android 中的任何其他浏览器,我不想在客户端使用移动浏览器访问时删除组件,但当且仅当它在移动设备上时我想这样做网络视图
    猜你喜欢
    • 2012-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多