浏览器&原型库中的版本? [英] Browser & version in prototype library?

查看:128
本文介绍了浏览器&原型库中的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯使用Atlas。最近我开始转换到jQuery,有时甚至是原型。我目前正在开发的项目是使用原型。

I am used to using Atlas. Recently i have started transitioning to jQuery and sometimes prototype. The project that i'm currently working on is using prototype.

在Prototype中,是否有一种简单的方法来获取浏览器名称和版本?我查看了API文档,似乎无法找到它。

In Prototype, is there an easy way to get the browser name and version? I've looked over the API documentation and can't seem to find it.

推荐答案

作为nertzy答案的完成,你可以使用以下功能添加检测IE版本的功能:

As a completion to nertzy's answer you can add the ability for detecting IE versions using this:

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 6;
Prototype.Browser.IE7 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5)) == 7;
Prototype.Browser.IE8 = Prototype.Browser.IE && !Prototype.Browser.IE6 && !Prototype.Browser.IE7;

另一方面,您还必须在服务器端检测用户代理详细信息。
无论如何,浏览器检测是一种严重缺陷的编写跨浏览器脚本的策略,只是在浏览器功能检测失败时使用。用户很容易改变他/她的用户代理详细信息。

On the other hand you have to detect user agent details on the server side, too. Anyways browser detection is a seriously flawed strategy for writing cross-browser scripts, that's just to be used when browser feature detection fails. It's pretty easy for a user to alter his/her user agent details.

这篇关于浏览器&原型库中的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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