• H5判断是手机端浏览器or原生App Webview


    参考:

    https://www.jianshu.com/p/a97fcc09f2e4

    https://blog.csdn.net/qq_15289761/article/details/107205278

    1. OC:这里我是在本身获取的字符串基础上拼接一个字符串,尽量不覆盖

    [webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id _Nullable userAgent, NSError * _Nullable error) {
            NSLog(@"%@",userAgent);
            
            NSMutableString *old = [NSMutableString stringWithFormat:@"%@",userAgent];
            
            NSString *lw = [NSString stringWithFormat:@"%@,%@",old, @"ios-lw-GG"];
            
            [webView setCustomUserAgent:lw];
            
        }];
    

     2. h5:  这里h5获取到和移动端约定的字符串,就可以做区分了

                var ua = navigator.userAgent.toLowerCase();
                log(ua)
    

     ------------------------------注意------------------

    在iOS 12.0, iOS 12.1上会有问题,如果参考:

    https://blog.csdn.net/qq_26697709/article/details/105961034

    这个人的解决办法, 在其他iOS 版本系统又有问题。所以我想到目前就直接在h5判断

    也很简单:(iphone手机上常用的浏览器就那几种,即使有十几种,那就都写出来就行了)

    <script>
             $(function(){
              
              $(".userAgent")[0].innerHTML = window.navigator.userAgent;
    
                if(window.navigator.userAgent.indexOf("Safari") != -1){
                    
                    $(".title")[0].innerHTML = "在浏览器";
                }
                else if(window.navigator.userAgent.indexOf("SougouMobileBrowser") != -1){
                  $(".title")[0].innerHTML = "在浏览器";
                }
                else if(window.navigator.userAgent.indexOf("SP-engine") != -1){
                  $(".title")[0].innerHTML = "在浏览器";
                }
                else if(window.navigator.userAgent.indexOf("MicroMessenger") != -1){
                  $(".title")[0].innerHTML = "在微信";
                }
                else{
                  $(".title")[0].innerHTML = "在App";
                }
          });
     </script>   
    
    此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935. 我的gitHub: (学习代码都在gitHub) https://github.com/nwgdegitHub/
  • 相关阅读:
    Maven安装教程详解
    eclipse配置apache tomcat运行时访问路径不需要项目名称
    Spring MVC Captcha 验证码
    Vue混入的详解
    Eclipse上传项目到Git
    mysql 8.0.11 中使用 grant ... identified by 时 error 1064 near 'identified by '密码'' at line 1
    转 js自定义事件——Event和CustomEvent
    tp隐藏入口文件
    php发送邮件
    【项目练习】控制器直接操作--登录
  • 原文地址:https://www.cnblogs.com/liuw-flexi/p/14986224.html
Copyright © 2020-2023  润新知