这篇文章主要介绍了关于利用javascript判断浏览器类型,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
判断浏览类型的相关方法
window.navigator.userAgent.toLowerCase()//将浏览器信息获取,并转成小写
function isBrowser(){
var agent=navigator.userAgent.toLowerCase()
console.log(agent)
if(agent.indexOf('chrome')>0){
alert("chrome浏览器")
}
if(agent.indexOf('firefox')>0){
alert("firefox浏览器")
}
if(agent.indexOf('trident')>0){
alert("IE浏览器")
}
}
isBrowser()上面代码可以判断ie,火狐,谷歌浏览器,但是 国内的QQ浏览器,搜狗浏览器运行的时候alert的结果是"Chrome浏览器"
function isBrowser(){
var agent=navigator.userAgent.toLowerCase()
console.log(agent)
System=function(){
if(agent.indexOf('qqbrowser')>0){//判断是qq浏览器还是其它浏览器
return alert("qq浏览器")
}
if(agent.indexOf("se 2.x")>0){
return alert("搜狗浏览器")
}
alert('chrome浏览器')
}
System()
if(agent.indexOf('firefox')>0){
alert("firefox浏览器")
}
if(agent.indexOf('trident')>0){
alert("IE浏览器")
}
}
isBrowser()360浏览器通过上面的方法并不能检测出是360浏览器
//application/vnd.chromium.remoting-viewer 可能为360特有 通过_mine判断是否是360
function isBrowser(){
var agent=navigator.userAgent.toLowerCase()
console.log(agent)
System=function(){
if(agent.indexOf('qqbrowser')>0){//判断是qq浏览器还是其它浏览器
return alert("qq浏览器")
}
if(agent.indexOf("se 2.x")>0){
return alert("搜狗浏览器")
}
var is360 = _mime("type", "application/vnd.chromium.remoting-viewer");
if (is360) {
return "360浏览器"
}
//检测是否是谷歌内核(可排除360及谷歌以外的浏览器)
//测试mime
function _mime(option, value) {
var mimeTypes = navigator.mimeTypes;
console.log(mimeTypes)
for (var mt in mimeTypes) {
if (mimeTypes[mt][option] == value) {
return true;
}
}
return false;
}
alert('chrome浏览器')
}
System()
if(agent.indexOf('firefox')>0){
alert("firefox浏览器")
}
if(agent.indexOf('trident')>0){
alert("IE浏览器")
}
}
isBrowser()这样就可以判断出是360浏览器
立即学习“Java免费学习笔记(深入)”;
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
以上就是利用javascript判断浏览器类型的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号