Skip to content Skip to sidebar Skip to footer

How Do I Write Browser Specific Javascript Code?

How do I write browser specific javascript code? for example just to make the code work for firefox or ie using javascript.

Solution 1:

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox

Read more in-depth here

Note that it's usually better to detect features not browsers, as you shouldn't care what browser the end user is using as long as it supports your's features.

Post a Comment for "How Do I Write Browser Specific Javascript Code?"