检测浏览器版本

var agentString = window.navigator.userAgent.toLowerCase();
	window.browser = {
		ie6		: ( agentString.indexOf( ' msie 6.' ) > -1 ),
		ie7		: ( agentString.indexOf( ' msie 7.' ) > -1 ),
		ie8		: ( agentString.indexOf( ' msie 8.' ) > -1 ),
		ie9		: ( agentString.indexOf( ' msie 9.' ) > -1 ),
		ie11	: ( agentString.indexOf( ' rv:11.0) like gecko' ) > -1 ),
		ie		: !!window.ActiveXObject,
		edge	: ( agentString.indexOf( ' edge/' ) > -1 ),

		/**
		 * 检测浏览器是否为firefox内核
		 * @name gecko
		 * @grammar UM.browser.gecko  => true|false
		 */
		gecko : ( agentString.indexOf( ' gecko/' ) > -1 ),

		/**
		 * 检测浏览器是否为Opera
		 * @name opera
		 * @grammar UM.browser.opera  => true|false
		 */
		opera	: ( !!window.opera && window.opera.version ),

		/**
		 * 检测浏览器是否为webkit内核
		 * @name webkit
		 * @grammar UM.browser.webkit  => true|false
		 */
		webkit	: ( agentString.indexOf( ' applewebkit/' ) > -1 ),

		/**
		 * 检测浏览器是否为mac系统下的浏览器
		 * @name mac
		 * @grammar UM.browser.mac  => true|false
		 * mozilla/5.0 (macintosh; intel mac os x 10_11_2) applewebkit/601.3.9 (khtml, like gecko) version/9.0.2 safari/601.3.9
		 */
		mac	: ( agentString.indexOf( 'macintosh' ) > -1 ),

		/**
		 * 检测浏览器是否处于怪异模式
		 * @name quirks
		 * @grammar UM.browser.quirks  => true|false
		 */
		quirks : ( document.compatMode == 'BackCompat' ),

		height: function () {
			var h = 0;
			if (window.browser.ie || window.browser.ie11) {
				h = $(window).height();
				if (h<=0)
					h = document.body.clientHeight;
			} else {
				h = $(window).height();
				if (h<=0)
					h = document.body.clientHeight;
			}
			return h;
		}
	};

你可能感兴趣的:(JavaScript)