For a client side method, look into using the window.navigator.userAgent string. More info can be found at window.navigator.userAgent.
Like Ray mentioned, in your case it might be cleaner to do this server side and use the $_SERVER['HTTP_USER_AGENT'] php variable.