js to get the browser type to judge

This article is the learning experience in webuploader.js, thanks for the open source, and the edge judgment of ie is added from it
/**
		 * @description Simple browser check result.
		 *
		 * * `webkit` webkit version number, if the browser is a non-webkit kernel, this property is `undefined`.
		 * * `chrome` chrome browser version number, if the browser is chrome, this property is `undefined`.
		 * * `ie` ie browser version number, if the browser is non-ie, this property is `undefined`.
		 * * `firefox` firefox browser version number, if the browser is non-firefox, this property is `undefined`.
		 * * `safari` safari browser version number, if the browser is non-safari, this property is `undefined`.
		 * * `opera` opera browser version number, if the browser is non-opera, this property is `undefined`.
		 *
		 * @property {Object} [browser]
		 */
		$scope.browser = function() {
			var ua = navigator.userAgent;
			var ret = {}, webkit = ua.match (/ WebKit \ / ([\ d.] +) /), chrome = ua
					.match(/Chrome\/([\d.]+)/)
					|| ua.match (/ CriOS \ / ([\ d.] +) /),

			ie = ua.match (/MSIE \ s ([\ d \.]+)/) || ua.match (/Edge \/([\ d.]+)/)
					|| ua.match(/(?:trident)(?:.*rv:([\w.]+))?/i), firefox = ua
					.match(/Firefox\/([\d.]+)/), safari = ua
					.match (/Safari \/([\ d.]+)/), opera = ua
					.match(/OPR\/([\d.]+)/);

			webkit && (ret.webkit = parseFloat(webkit[1]));
			chrome && (ret.chrome = parseFloat(chrome[1]));
			ie && (ret.ie = parseFloat(ie[1]));
			firefox && (ret.firefox = parseFloat(firefox[1]));
			safari && (ret.safari = parseFloat(safari[1]));
			opera && (ret.opera = parseFloat(opera[1]));

			return ret;
		};
		if ($scope.browser().ie) {
			alert("I am ie");
		}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326375465&siteId=291194637
Recommended