如何检测Google Chrome浏览器?例如,我可以使用以下标记检测Internet Explorer:
<!--[if lte IE]>
<link href="ie_only.css" rel="stylesheet" type="text/css" />
<![endif]-->我有一个想法:
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;但也许有人有更好的解决方案?
更新:我的页面显示错误只与Chrome浏览器,所以我需要加载(只与chrome)特殊的css文件与更新
发布于 2010-12-10 06:22:22
如上所述,您应该检测feature compatibility,而不是浏览器。也就是说,在很少的情况下,你需要在你的CSS中定位WebKit浏览器。例如,我有一个小的字体大小/渲染问题,只在Chrome/Safari中出现,我修复了它,如下所示:
@media screen and (-webkit-min-device-pixel-ratio:0) {
/* Chrome- and Safari-specific CSS here*/
}另一个警告:如果一些东西在Chrome/Safari中呈现不正确,但在Firefox中不正确,那么很可能你有其他一些潜在的问题,例如无效的标记。在使用上面的方法之前,请确保验证您的HTML并检查是否存在其他问题。
发布于 2012-07-14 09:17:52
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if (is_chrome) {
document.write("Yaii it is Chrome only")
}来自:"Simple way to detect chrome browser using javascript"
https://stackoverflow.com/questions/4401957
复制相似问题