虽然jQuery 对各种浏览器的兼容已经做的很好 但还是会碰到要检测浏览器才能搞定的情况

比如用 $.ajax 来调取 xml 并解析的例子中

$.ajax({
     type:
"GET",
     url:
"questions.xml",
     dataType:
'xml',
     timeut:
1500,
     error:
function(){alert("Error loading xml!")},   
     success:
function(xml){//function goes herejs常用脚本 判断浏览器

})

在本地用静态环境测试 IE 总会警告错误,FF 和其他浏览器却正常调取解析,如果用绝对地址

$.ajax({
     type:
"GET",
     url:
"http://www.xxx.com/focus/kikx/questions.xml",
     dataType:
'xml'js常用脚本 判断浏览器..
则IE 调取解析正常,而Firefox却不能调取到XML 好吧 我还是来判断下浏览器吧 :    

下面是检测浏览器的一段脚本 写的很精简 很好用:


{
    ve : ua.match(/.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/)[1],
    ie : /msie/.test(ua) && !/opera/.test(ua),
    op : 
/opera/.test(ua),
    sa : 
/version.*safari/.test(ua),
    ch : 
/chrome/.test(ua),
    ff : 
/gecko/.test(ua) && !/webkit/.test(ua)
};
if(binfo.ie){
alert(
"IE");
}
if(binfo.op){
alert(
"Opera");
}
if(binfo.sa){
alert(
"Safri");
}
if(binfo.ch){
alert(
"Chrome");
}
if(binfo.ff){
alert(
"Firefox");

相关文章:

  • 2022-12-23
  • 2021-12-01
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-09-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
相关资源
相似解决方案