我有这样的偏好:
<!DOCTYPE overlay SYSTEM "chrome://inlinetrans/locale/options.dtd">
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
id="translate-preferences"
title="&options.title;"
buttons="accept, cancel"
style="padding:0px; margin:0px;"
ondialogaccept="options.save()"
onload="options.init();"
onunload="options.deconstruct();">
<script src="chrome://inlinetrans/content/options.js" />
<description value="&options.desc;"
style="
background: #fff url('chrome://inlinetrans/skin/options.png') no-repeat;
min-width:400px;
min-height:40px;
padding-left:55px;
padding-top:10px;
margin:0px;
border-bottom: 2px solid #757575;
font-size:1.5em;"/>
<vbox style="padding:10px;">
<groupbox>
<caption label="&options.ui;"/>
<label value="&options.results.desc;"/>
<radiogroup id="display.results" style="padding-left:20px;">
<radio id="results.cat" value="currenttab" label="&options.results.cat;"/>
<radio id="results.noncat" value="newwindow" label="&options.results.noncat;"/>
</radiogroup>
</groupbox>
</vbox>
</dialog>
这是我做的偏好处理程序,但我不确定它是否有效:
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var t_prefBranch = prefService.getBranch("extensions.inlinetrans.");
var options = {
result : String,
init : function() {
this.updatePrefs()
t_prefBranch.setCharPref("optionopen", true)
var Displayresults = document.getElementById("results." + this.result)
Displayresults.setAttribute("selected", true);
},
updatePrefs : function() {
this.result = t_prefBranch.getCharPref("results")
},
save : function() {
var savepref = document.getElementById("display.results").value
if (savepref != "") {
t_prefBranch.setCharPref("results", savepref)
}
},
reloadOptions : function() {
this.save()
this.init()
}
}
非常感谢你的帮助