//判断浏览器function myBrowser() {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("Edge") > -1; //判断是否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版本过低return "IE";}if (isOpera) {return "Opera";}if (isEdge) {return "Edge";}if (isFF) {return "FF";}if (isSafari) {return "Safari";}if (isChrome) {return "Chrome";}}var Browser = '';var ua = navigator.userAgent.toLowerCase();//获取判断用的对象if (ua.match(/MicroMessenger/i) == "micromessenger") {//weixinBrowser = 'WX';}else if (navigator.userAgent.indexOf('UCBrowser') > -1) {// UC MQQBrowserBrowser = 'UC';}else if (navigator.userAgent.indexOf('MQQBrowser') > -1) {// MQQBrowserBrowser = 'QQ';}else {// 获取浏览器Browser = myBrowser();}//判断浏览器if (Browser == 'Safari') {console.log(Browser)}else if (Browser == 'Chrome') {console.log(Browser)}else if (Browser == 'WX') {console.log('微信')}else if (Browser == 'UC') {console.log('UC 浏览器')}else if (Browser == 'QQ') {console.log('QQ 浏览器')}else {console.log('Chrome 浏览器')}
1200字范文,内容丰富有趣,写作的好帮手!