nsIPropertyBag 编辑

xpcom/ds/nsIPropertyBag.idlScriptable This interface is used to store a set of properties. Inherits from: nsISupports Last changed in Gecko 1.0

Method overview

nsIVariant getProperty(in AString name);

Attributes

AttributeTypeDescription
enumeratornsISimpleEnumeratorGet a nsISimpleEnumerator whose elements are nsIProperty objects. Read only.

Methods

getProperty()

Get a property value for the given name.

nsIVariant getProperty(
  in AString name
);
Parameters
name
The name to return the matching property.
Return value

The property matching the given name.

Exceptions thrown
NS_ERROR_FAILURE
If a property with that name doesn't exist.

Examples

Get User Agent Information (Operating System Specifics.

The windowscope is not always accessible so the window.navigator cannot be accessed. Goodies obtained from window.navigatorare:

appCodeName:"Mozilla"
appName:"Netscape"
appVersion:"5.0 (Windows)"
battery:BatteryManager
buildID:"20140529161749"
cookieEnabled:true
doNotTrack:"yes"
geolocation:Geolocation
language:"en-US"
mimeTypes:MimeTypeArray
mozAlarms:null
mozApps:XPCWrappedNative_NoHelper
mozCameras:CameraManager
mozConnection:MozConnection
mozContacts:ContactManager
mozId:null
mozKeyboard:XPCWrappedNative_NoHelper
mozPay:null
mozPermissionSettings:null
mozPhoneNumberService:PhoneNumberService
mozPower:MozPowerManager
mozTCPSocket:null
onLine:true
oscpu:"Windows NT 5.1"
platform:"Win32"
plugins:PluginArray
product:"Gecko"
productSub:"20100101"
userAgent:"Mozilla/5.0 (Windows NT 5.1; rv:30.0) Gecko/20100101 Firefox/30.0"
vendor:""
vendorSub:""
__proto__:NavigatorPrototype

From here we can easily see the Operating System version. Services.appinfo.OS simply tells us WINNTonly, this is not helpful to differentiate between Windows XP, Vista, 7, etc. To do this use nsIPropertyBag:

Services.sysinfo.getProperty("version"); //output 5.1
Services.sysinfo.getProperty("name"); //output Windows_NT
Services.sysinfo.getProperty("arch"); //output x86
Services.sysinfo.getProperty("hasWindowsTouchInterface"); //outputs false or true if windows touch is there

Consult the DXR (https://dxr.mozilla.org/mozilla-release/source/xpcom/base/nsSystemInfo.cpp) for the properties supported. Also pay attention to their platform-specific meaning (e.g. on Android there is versionand kernel_version).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:104 次

字数:4728

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文