JavaScript Browser Detection

by Tweak on June 12, 2009
in Javascript

Browser detection is a vital tool when your web site looks different or does not function correctly when viewed in different browsers. Using Javascript, you can redirect viewers to different pages or display different content depending on a user’s browser.

We will use the index of function and the navigator object in order to preform browser detection. What we first need to do is to determine what type of browser the user is using. To do this, we use the navigator.userAgent function to determine the type (application) being used. We create a variable called browsername to do this. Here is what the script looks like so far: Read more…