Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at https://viewsourceconf.org

Services.jsm

The Services.jsm  模块提供了一系列的javascript模块,用来简化各种常用的操作.

在使用它们之前,你必须首先将Services模块导入到自己的作用域内:

Components.utils.import("resource://gre/modules/Services.jsm");

然后你可以通过服务访问器来轻松的从Services对象导出所需要的模块. 例如,要想获取一个preferences服务,你可以用下面的语句:

var prefsService = Services.prefs;

服务访问器

服务访问器 服务接口 服务名
appinfo nsIXULAppInfo
nsIXULRuntime
Application information service
console nsIConsoleService Error console service
contentPrefs nsIContentPrefService

Content Preferences service

cookies nsICookieManager2

Cookie Manager 2 service

dirsvc nsIDirectoryService
nsIProperties
Directory service
droppedLinkHandler nsIDroppedLinkHandler Dropped link handler service
eTLD nsIEffectiveTLDService

EffectiveTLD service

io nsIIOService
nsIIOService2
I/O Service
locale nsILocaleService Locale service
logins nsILoginManager

Password Manager service

obs nsIObserverService Observer service
perms nsIPermissionManager Permission manager service
prefs nsIPrefBranch
nsIPrefBranch2
nsIPrefService
Preferences service
prompt nsIPromptService Prompt service
scriptloader mozIJSSubScriptLoader JavaScript subscript loader service
search nsIBrowserSearchService Browser search service1
startup nsIAppStartup Application startup service
storage mozIStorageService Storage API service
strings nsIStringBundleService String bundle service
sysinfo nsIPropertyBag2 System info service
telemetry nsITelemetry Telemetry service
tm nsIThreadManager Thread Manager service
urlFormatter nsIURLFormatter

URL Formatter service

vc nsIVersionComparator Version comparator service
wm nsIWindowMediator Window mediator service
ww nsIWindowWatcher Window watcher service
DOMRequest nsIDOMRequestService DOMRequest service
cpmm nsIFrameMessageManager Child Process Message Manager
ppmm nsIFrameMessageManager Parent Process Message Manager

Thunderbird 和 SeaMonkey中该特性不可用.

相关链接

文档标签和贡献者

 此页面的贡献者: ziyunfei
 最后编辑者: ziyunfei,