扫码关注官方订阅号
开发一个 webapp 可能运行在微信里面或者是其他浏览器,也可能是android、ios app,或是其他的平台,那么问题来了:js如何判断当前运行环境是ios webview还是android webview?
学习是最好的投资!
user-agentzepto对useragent的嗅探
var os = this.os = {}, browser = this.browser = {}, webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/), android = ua.match(/(Android);?[\s\/]+([\d.]+)?/), osx = !!ua.match(/\(Macintosh\; Intel /), ipad = ua.match(/(iPad).*OS\s([\d_]+)/), ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/), iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/), webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/), win = /Win\d{2}|Windows/.test(platform), wp = ua.match(/Windows Phone ([\d.]+)/), touchpad = webos && ua.match(/TouchPad/), kindle = ua.match(/Kindle\/([\d.]+)/), silk = ua.match(/Silk\/([\d._]+)/), blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/), bb10 = ua.match(/(BB10).*Version\/([\d.]+)/), rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/), playbook = ua.match(/PlayBook/), chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/), firefox = ua.match(/Firefox\/([\d.]+)/), firefoxos = ua.match(/\((?:Mobile|Tablet); rv:([\d.]+)\).*Firefox\/[\d.]+/), ie = ua.match(/MSIE\s([\d.]+)/) || ua.match(/Trident\/[\d](?=[^\?]+).*rv:([0-9.].)/), webview = !chrome && ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/), safari = webview || ua.match(/Version\/([\d.]+)([^S](Safari)|[^M]*(Mobile)[^S]*(Safari))/)
userAgent?
iOS里面WKWebView的属性 userAgent只支持9.0以上的。这就很尴尬了,9.0系统以下调用直接崩溃....
就 useragent ,还没有见到过使用其他判断的。。。暂时还没见到能够识别自行修改useragent的网页,我的修改useragent的扩展一直用的没有什么问题。
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
user-agent
zepto对useragent的嗅探
userAgent?
iOS里面WKWebView的属性 userAgent只支持9.0以上的。
这就很尴尬了,9.0系统以下调用直接崩溃....
就 useragent ,还没有见到过使用其他判断的。。。暂时还没见到能够识别自行修改useragent的网页,我的修改useragent的扩展一直用的没有什么问题。