简体   繁体   English

如何检查浏览器兼容性

[英]How to check browser compatibility

I've written a web app that uses features that make it incompatible with IE and require minimum versions of Firefox and Chrome. 我编写了一个Web应用程序,它使用的功能使其与IE不兼容,并且需要最低版本的Firefox和Chrome。 To check browser compatibility, I'm getting the User-Agent from the headers of the request with web.py and checking the output with a simple regex. 为了检查浏览器兼容性,我从web.py的请求标题中获取User-Agent,并使用简单的正则表达式检查输出。

I'm worried though, that changes to the way Chrome or Firefox declares it's User-Agent might break my regex. 我担心,改变Chrome或Firefox宣称它的用户代理的方式可能会破坏我的正则表达式。 Also, since I'm explicitly requiring Firefox or Chrome, I'm probably excluding some browsers that might otherwise be able to use the site. 此外,由于我明确要求使用Firefox或Chrome,我可能会排除某些可能使用该网站的浏览器。

Is checking User-Agent the right way to go? 检查User-Agent是否正确? How should I go about checking compatibility to ensure only browsers that have sufficient functionality are served? 我应该如何检查兼容性以确保只提供具有足够功能的浏览器?

You'd better do it on client side, browser sniffing is considered bad. 你最好在客户端做,浏览器嗅探被认为是坏事。 The best practice is using conditional comments to add ie# (Internet Explorer version) classname on html to be able to write separate css styles for it, and use modernizr to detect supported features. 最佳做法是使用条件注释在html上添加ie(Internet Explorer版本)类名,以便能够为其编写单独的css样式,并使用modernizr检测支持的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM