Home > Web Front-end > JS Tutorial > JavaScript identifies various browsers through navigator.userAgent_javascript skills

JavaScript identifies various browsers through navigator.userAgent_javascript skills

WBOY
Release: 2016-05-16 17:18:48
Original
1443 people have browsed it

原理:根据navigator.userAgent返回值识别

实现:

复制代码 代码如下:

function validBrowser(){
var u_agent = navigator.userAgent;
var browser_name='Failed to identify the browser';
if(u_agent.indexOf('Firefox')>-1){
browser_name='Firefox';
}else if(u_agent.indexOf('Chrome')>-1){
browser_name='Chrome';
}else if(u_agent.indexOf('Trident')>-1&&u_agent.indexOf('rv:11')>-1){
browser_name='IE11';
}else if(u_agent.indexOf('MSIE')>-1&&u_agent.indexOf('Trident')>-1){
browser_name='IE(8-10)';
}else if(u_agent.indexOf('MSIE')>-1){
browser_name='IE(6-7)';
}else if(u_agent.indexOf('Opera')>-1){
browser_name='Opera';
}else{
browser_name =',info:' u_agent;
}
document.write('browser_name:' browser_name '
');
document.write('u_agent:' u_agent '
');
}

3、附几种浏览的user_agent..像360的兼容模式用的是IE、极速模式用的是chrom的内核
JavaScript identifies various browsers through navigator.userAgent_javascript skills 
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template