How do I write browser specific javascript code? [closed]

99封情书 提交于 2019-12-24 01:26:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!