Determining the browser version of a visitor

MooTools is cross-browser compliant, but CSS is not always as nice; let's figure out what browser is visiting us.

How to do it...

Create a string that has browser and platform particulars in it.

var browser_info = 'Your browser info: '+
Browser.name+' '+
Browser.version+' on '+
Browser.Platform.name;

How it works...

MooTools works regular expression magic on the navigator.userAgent. See this snippet from the source:

var ua = navigator.userAgent.toLowerCase(), platform = navigator.platform.toLowerCase(), UA = ua.match(/(opera|ie|firefox|chrome|version)[s/:]([wd.]+)?.*?( safari|version[s/:]([wd.]+)|$)/) || [null, 'unknown', 0], mode = UA[1] == 'ie' && document.documentMode; var Browser = this.Browser = { ...

Get MooTools 1.3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.