js獲取瀏覽器版本
阿新 • • 發佈:2019-02-20
function BrowserType()
{
var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串
var isOpera = userAgent.indexOf("Opera") > -1; //判斷是否Opera瀏覽器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判斷是否IE瀏覽器
var isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判斷是否IE的Edge瀏覽器
var isFF = userAgent.indexOf("Firefox") > -1; //判斷是否Firefox瀏覽器
var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1; //判斷是否Safari瀏覽器
var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1; //判斷Chrome瀏覽器
if (isIE)
{
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7)
{ return "IE7";}
else if(fIEVersion == 8)
{ return "IE8";}
else if(fIEVersion == 9)
{ return "IE9";}
else if(fIEVersion == 10)
{ return "IE10";}
else if(fIEVersion == 11)
{ return "IE11";}
else
{ return "0"}//IE版本過低
}//isIE end
if (isFF) { return "FF";}
if (isOpera) { return "Opera";}
if (isSafari) { return "Safari";}
if (isChrome) { return "Chrome";}
if (isEdge) { return "Edge";}
}//myBrowser() end
//判斷是否是IE瀏覽器
function isIE()
{
var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判斷是否IE瀏覽器
if(isIE)
{
return "1";
}
else
{
return "-1";
}
}
//判斷是否是IE瀏覽器,包括Edge瀏覽器
function IEVersion()
{
var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判斷是否IE瀏覽器
ar isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判斷是否IE的Edge瀏覽器
if(isIE)
{
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7)
{ return "IE7";}
else if(fIEVersion == 8)
{ return "IE8";}
else if(fIEVersion == 9)
{ return "IE9";}
else if(fIEVersion == 10)
{ return "IE10";}
else if(fIEVersion == 11)
{ return "IE11";}
else
{ return "0"}//IE版本過低
}
else if(isEdge)
{
return "Edge";
}
else
{
return "-1";//非IE
}
}
var a=BrowserType();
console.info(a);
{
var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串
var isOpera = userAgent.indexOf("Opera") > -1; //判斷是否Opera瀏覽器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判斷是否IE瀏覽器
var isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判斷是否IE的Edge瀏覽器
var isFF = userAgent.indexOf("Firefox") > -1; //判斷是否Firefox瀏覽器
var isSafari = userAgent.indexOf("Safari") > -1 && userAgent.indexOf("Chrome") == -1; //判斷是否Safari瀏覽器
var isChrome = userAgent.indexOf("Chrome") > -1 && userAgent.indexOf("Safari") > -1; //判斷Chrome瀏覽器
if (isIE)
{
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7)
{ return "IE7";}
else if(fIEVersion == 8)
{ return "IE8";}
else if(fIEVersion == 9)
{ return "IE9";}
else if(fIEVersion == 10)
{ return "IE10";}
else if(fIEVersion == 11)
{ return "IE11";}
else
{ return "0"}//IE版本過低
}//isIE end
if (isFF) { return "FF";}
if (isOpera) { return "Opera";}
if (isSafari) { return "Safari";}
if (isChrome) { return "Chrome";}
if (isEdge) { return "Edge";}
}//myBrowser() end
//判斷是否是IE瀏覽器
function isIE()
{
var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判斷是否IE瀏覽器
if(isIE)
{
return "1";
}
else
{
return "-1";
}
}
//判斷是否是IE瀏覽器,包括Edge瀏覽器
function IEVersion()
{
var userAgent = navigator.userAgent; //取得瀏覽器的userAgent字串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判斷是否IE瀏覽器
ar isEdge = userAgent.indexOf("Windows NT 6.1; Trident/7.0;") > -1 && !isIE; //判斷是否IE的Edge瀏覽器
if(isIE)
{
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7)
{ return "IE7";}
else if(fIEVersion == 8)
{ return "IE8";}
else if(fIEVersion == 9)
{ return "IE9";}
else if(fIEVersion == 10)
{ return "IE10";}
else if(fIEVersion == 11)
{ return "IE11";}
else
{ return "0"}//IE版本過低
}
else if(isEdge)
{
return "Edge";
}
else
{
return "-1";//非IE
}
}
var a=BrowserType();
console.info(a);