Principle: Recognition Based on the return value of navigator. userAgent
Implementation:
Copy codeThe Code is as follows:
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 ('chromi')>-1 ){
Browser_name = 'chrome ';
} Else if (u_agent.indexOf ('trigger')>-1 & u_agent.indexOf ('rv: 11')>-1 ){
Browser_name = 'ie11 ';
} Else if (u_agent.indexOf ('msie ')>-1 & u_agent.indexOf ('trigger')>-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 +' <br> ');
Document. write ('U _ agent: '+ u_agent +' <br> ');
}
3. Attach several browsing user_agent .. For example, The compatible mode of 360 uses IE, and the fast mode uses the chrom kernel.