drvjlec1767 2013-12-30 16:28
浏览 494
已采纳

要求Web应用程序的最低浏览器版本

I have a web application in PHP which in the frontend requires some more modern browser features like the MutationObserver. As stated on the site only very new browsers support this feature. The same holds for some HTML5-features I need to rely on.

What I would like to achieve now, is to check server-side with the UserAgent-String which browser the user is running, and if it is below a specific version, redirect him to an info-page where he is informed that he should use a newer browser.

I've been trying now for a while to setup appropriate Regex-Expressions to check the UA-strings against. However, I'm stuck a little bit as the browser manufacturers don't always keep a clean schema - e.g. let's say for an Opera-Browser I would require a minimum version of 12.

  • Opera 12.14 example 1: Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14
  • Opera 12.14 example 2: Mozilla/5.0 (Windows NT 6.0; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 12.14
    This could also be Firefox 4.0.
  • Opera 11.51: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; de) Opera 11.51
    This could also be Internet Explorer 9.0.

Also tracking for the same browser and version is tricky as shown in the two examples for Opera 12.14: either it is "Version/12.14" or "Opera 12.14" or some other pretty "random" string. For other browsers the problem is quite similar.

So the question is: how would you proceed?

Method 1:
useragentstring.com has an API that I could query each time a user accesses the welcome page and/or logs in. I'm not sure whether this is a good idea in matters of security and app performance.

Method 2:
PHP's get_browser() function in conjunction with browscap.ini. This method can't distinguish between desktop and mobile browsers.

Method 3:
An alternative to Method 2 could be phpbrowscap where you can define your own browsercap.ini without depending on a browscap.ini somewhere on the server where you don't have access to.

Or any other method?

I'd be happy for some comments.

  • 写回答

3条回答 默认 最新

  • dongliming2416 2013-12-30 16:36
    关注

    Rather than keeping your own database of user agents and features, which can be hard to get right, and a pain to keep updated, many developers these days use JavaScript to query whether a feature is available in the browser.

    The Modernizr JavaScript library makes this relatively straightforward. This article goes into more depth about why this approach is a good idea, and shows a few alternative methods of doing feature detection if you don't want to rely on a library.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?