我如何写浏览器的JavaScript特定code? [英] How do I write browser specific javascript code?

查看:98
本文介绍了我如何写浏览器的JavaScript特定code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样写的浏览器的JavaScript特定code?结果
例如只是为了让用于Firefox的code的工作或使用JavaScript IE浏览器。


解决方案

 如果(/ MSIE(\\ D + \\ \\ D +); /测试(navigator.userAgent的)){/ /测试MSIE XX;如果(/火狐[\\ / \\ S](\\ D + \\。\\ D +)/。测试(navigator.userAgent的)){//为Firefox测试

更多深入这里

请注意,它通常是更好的检测功能的浏览器不,你不应该关心,因为它支持你的功能,最终用户只要使用的是什么浏览器。

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

解决方案

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.

这篇关于我如何写浏览器的JavaScript特定code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆