问题
How do I write browser specific javascript code?
for example just to make the code work for firefox or ie using javascript.
回答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.
来源:https://stackoverflow.com/questions/14721237/how-do-i-write-browser-specific-javascript-code