MooTools1.3.1 API(Core)学习及试译(四)——Browser

写在前面:由于自身英语水平有限,所以翻译不敢保证能让所有人都理解,如果您在阅读中发现什么疑问,请务必及时查看官方API,以免误导。另外,有部分是未经翻译的,一方面是因为找不到合适的中文描述之,还有就是有的地方看英文更易懂~

续前面三篇,本篇关于Browser对象:提供一些检测浏览器版本、运行平台的方法

//Object: Browser
//附加到Browser对象上的一些浏览器属性以检测浏览器及运行平台

//Browser.Features
Browser.Features.xpath - (boolean) 如果浏览器支持通过XPath查询DOM时返回true
Browser.Features.air - (boolean) 如果浏览器支持AIR时返回true
Browser.Features.query - (boolean) 如果浏览器支持querySelectorAll时返回true
Browser.Features.json - (boolean) 如果浏览器含有本地的JSON对象时返回true
Browser.Features.xhr - (boolean) 如果浏览器支持本地的XMLHTTP对象时返回true

//Browser.name
//把浏览器名称作为字符串返回,就像以下的布尔值反映的属性名一样:
Browser.ie - (boolean) True if the current browser is Internet Explorer
Browser.firefox - (boolean) True if the current browser is Firefox
Browser.safari - (boolean) True if the current browser is Safari
Browser.chrome - (boolean) True if the current browser is Chrome
Browser.opera - (boolean) True if the current browser is Opera
除上面的属性外,还可以传入一个包含主要版本号的属性名(如Browser.ie6、Browser.firefox2...)

alert(Browser.name); 
// Alerts "ie" in Internet Explorer, "firefox" in Mozilla Firefox, "chrome" in Google Chrome, "safari" or "opera".
 
if (Browser.ie){
    // This code will only run in IE
}
 
if (Browser.firefox2){
    // This code will only run in Firefox 2
}
 
if (Browser.ie6 || Browser.ie7){
    // Please upgrade your browser
}

如果ie文档设置了向后兼容模式(如腾讯首页:<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />),Browser对象将像对待之前版本的浏览器一样对待浏览器

//Browser.version
//显示浏览器版本号为数值

alert(Browser.version);//如果是firefox 4的话显示4...

//Browser.Platform
//运行平台
Browser.Platform.mac - (boolean) True if the platform is Mac.
Browser.Platform.win - (boolean) True if the platform is Windows.
Browser.Platform.linux - (boolean) True if the platform is Linux.
Browser.Platform.ios - (boolean) True if the platform is iOS.
Browser.Platform.android - (boolean) True if the platform is Android
Browser.Platform.webos - (boolean) True if the platform is WebOS
Browser.Platform.other - (boolean) True if the platform is neither Mac, Windows, Linux, Android, WebOS nor iOS.
Browser.Platform.name - (string) The name of the platform

alert(Browser.Platform.name);//如果是Windows的话显示win

//Browser.Plugins
Browser.Plugins.Flash - (boolean) - True if Flash is present
Browser.Plugins.Flash.version - (number) flash 插件的版本
Browser.Plugins.Flash.build - (number) build 插件的编译器版本

//Browser.Request
Browser.Request - (object) The XMLHTTP object or equivalent

//Browser.exec
//在浏览器上下文执行传入的字符串
Browser.exec('alert("Moo!")');
posted @ 2011-04-05 23:46  chemdemo  阅读(331)  评论(0编辑  收藏  举报