断浏览器及设备版本

var myView = 11;

function myBrowser() {

var userAgent = navigator.userAgent;

var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器

var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器

var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器 

var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;

var isFF = userAgent.indexOf("Firefox") > -1; //判断是否Firefox浏览器

var isSafari = userAgent.indexOf("Safari") > -1; //判断是否Safari浏览器

if (isIE) {

var IE5 = IE55 = IE6 = IE7 = IE8 = IE9 = IE10 = IE11 = false;

var reIE = new RegExp("MSIE (\\d+\\.\\d+);");

reIE.test(userAgent);

var fIEVersion = parseFloat(RegExp["$1"]);

IE55 = fIEVersion == 5.5;

IE6 = fIEVersion == 6.0;

IE7 = fIEVersion == 7.0;

IE8 = fIEVersion == 8.0;

IE9 = fIEVersion == 9.0;

IE10 = fIEVersion == 10;

//IE9 = fIEVersion == 9.0;

if (IE55) { return "IE55"; }

if (IE6) { return "IE6"; }

if (IE7) { return "IE7"; }

if (IE8) { return "IE8"; }

if (IE9) { return "IE9"; }

if (IE10) { return "IE10"; }

} //isIE end

if (isIE11) { return "IE11"; }

if (isEdge) { return "Edge"; }

if (isFF) { return "FF"; }

if (isOpera) { return "Opera"; }

} //myBrowser() end

//以下是调用上面的函数

if (myBrowser() == "FF") { myView = 11; }

if (myBrowser() == "Opera") { myView = 11; }

if (myBrowser() == "Safari") { myView = 11; }

if (myBrowser() == "IE55") { myView = 5; }

if (myBrowser() == "IE6") { myView = 6; }

if (myBrowser() == "IE7") { myView = 7; }

if (myBrowser() == "IE8") { myView = 8; }

if (myBrowser() == "IE9") { myView = 9; }

if (myBrowser() == "IE10") { myView = 10; }

if (myBrowser() == "IE11") { myView = 11; }

if (myBrowser() == "Edge") { myView = 11; }

function IsSP() {

var userAgentInfo = navigator.userAgent;

var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];

var flag = false;

for (var v = 0; v < Agents.length; v++) {

if (userAgentInfo.indexOf(Agents[v]) > 0) {

flag = true;

break;

}

}

return flag;

}

function IsPC() {

var userAgentInfo = navigator.userAgent;

var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];

var flag = true;

for (var v = 0; v < Agents.length; v++) {

if (userAgentInfo.indexOf(Agents[v]) > 0) {

flag = false;

break;

}

}

return flag;

}

function IsPCandSp() {

var userAgentInfo = navigator.userAgent;

var Agents = ["iPad", "iPod"];

var flag = true;

for (var v = 0; v < Agents.length; v++) {

if (userAgentInfo.indexOf(Agents[v]) > 0) {

flag = false;

break;

}

}

return flag;

}

function IsPCandIpad() {

var userAgentInfo = navigator.userAgent;

var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone"];

var flag = true;

for (var v = 0; v < Agents.length; v++) {

if (userAgentInfo.indexOf(Agents[v]) > 0) {

flag = false;

break;

}

}

return flag;

}

你可能感兴趣的:(断浏览器及设备版本)