O'Reilly logo

MooTools 1.3 Cookbook by Jay Larry G. Johnston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 = { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required