Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Restores `$.browser` functionality removed in jQuery 1.9
jQuery.uaMatch = (ua) ->
ua = ua.toLowerCase()
match = /(chrome)[ \/]([\w.]+)/.exec(ua) or
/(webkit)[ \/]([\w.]+)/.exec(ua) or
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) or
/(msie) ([\w.]+)/.exec(ua) or
ua.indexOf("compatible") < 0 and /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) or []
browser: match[1] or ''
version: match[2] or '0'
matched = jQuery.uaMatch(navigator.userAgent)
browser = {}
if matched.browser
browser[matched.browser] = true
browser.version = matched.version
browser.webkit = true
else if browser.webkit
browser.safari = true
jQuery.browser = browser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.