[英]How can I find out which browser a user is using?
I would like to show a pop-up telling the user if their browser is outdated. 我想显示一个弹出窗口,告诉用户他们的浏览器是否已过时。 How can I find out what browser they are using in javascript?
如何在javascript中找出他们使用的浏览器?
Check out this browser detection script: 查看此浏览器检测脚本:
http://www.quirksmode.org/js/detect.html http://www.quirksmode.org/js/detect.html
function BrowserDetection() {
if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
var ffversion = new Number(RegExp.$1) ;
}
else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
var ieversion = new Number(RegExp.$1);
}
else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
var chromeversion = new Number(RegExp.$1);
// capture x.x portion and store as a number
}
else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
var oprversion = new Number(RegExp.$1)
}
else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
var safariversion = new Number(RegExp.$1);
}
}
Then after finding the version, u will compare and display popup according to your need. 然后在找到版本后,您将根据需要比较并显示弹出窗口。
Don't detect browsers , detect browser features . 不检测浏览器 ,检测浏览器功能 。 There's a good discussion on Stack Overflow already:
已经对Stack Overflow进行了很好的讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.