nsIPropertyBag 编辑
xpcom/ds/nsIPropertyBag.idl
Scriptable This interface is used to store a set of properties. Inherits from: nsISupports
Last changed in Gecko 1.0Method overview
nsIVariant getProperty(in AString name); |
Attributes
Attribute | Type | Description |
enumerator |
| Get 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 window
scope is not always accessible so the window.navigator
cannot be accessed. Goodies obtained from window.navigator
are:
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 WINNT
only, 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 version
and kernel_version
).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论