Home > Web Front-end > JS Tutorial > body text

js recognizes the code of uc browser_javascript skills

WBOY
Release: 2016-05-16 15:33:16
Original
1652 people have browsed it

It’s actually quite simple

if(navigator.userAgent.indexOf('UCBrowser') > -1) {
alert("uc浏览器");
}else{
//不是uc浏览器执行的操作
}
Copy after login

If you want to test the characteristics of a certain browser, you can obtain it through the following methods

JS gets browser information
Browser code name: navigator.appCodeName
Browser name: navigator.appName
Browser version number: navigator.appVersion
Support for Java: navigator.javaEnabled()
MIME types (array): navigator.mimeTypes
System platform: navigator.platform
Plugins (array): navigator.plugins
User agent: navigator.userAgent

Relatively complete

<script type="text/javascript"> 
document.write('浏览器判別:');
var OsObject=navigator.userAgent;
// 包含「Opera」文字列 
if(OsObject.indexOf("Opera") != -1) 
{ 
   document.write('您的浏览器是Opera吧?'); 
} 
// 包含「MSIE」文字列 
else if(OsObject.indexOf("MSIE") != -1) 
{ 
   document.write('您的浏览器是Internet Explorer吧?'); 
} 
// 包含「chrome」文字列 ,不过360浏览器也照抄chrome的UA

else if(OsObject.indexOf("Chrome") != -1) 
{ 
  document.write('您的浏览器是chrome或360浏览器吧?'); 
}
// 包含「UCBrowser」文字列 
else if(OsObject.indexOf("UCBrowser") != -1) 
{ 
  document.write('您的浏览器是UCBrowser吧?'); 
}
// 包含「BIDUBrowser」文字列 
else if(OsObject.indexOf("BIDUBrowser") != -1) 
{ 
  document.write('您的浏览器是百度浏览器吧?'); 
}
// 包含「Firefox」文字列 
else if(OsObject.indexOf("Firefox") != -1) 
{ 
  document.write('您的浏览器是Firefox吧?'); 
}
// 包含「Netscape」文字列 
else if(OsObject.indexOf("Netscape") != -1)
{ 
  document.write('您的浏览器是Netscape吧?'); 
} 
// 包含「Safari」文字列 
else if(OsObject.indexOf("Safari") != -1) 
{ 
   document.write('您的浏览器是Safari 吧?'); 
} 
else{ 
  document.write('无法识别的浏览器。'); 
} 
</script> 
Copy after login

Many browsers are now based on the chrome browser, such as 360, Cheetah Browser, etc.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!