In one of my Web Development classes we where asked to create a script that detects NE4,NE6+,IE4,IE6+ Browsers that display a compatable CSS script for each browser.
You'll want to use Conditionizr, which features robust test/detect add-ons for this: http://conditionizr.com
For example:
conditionizr.add('safari', [], function () { return /constructor/i.test(window.HTMLElement); });