感謝Wladimir Palant
用於指明瞭方向,但它仍然花了我好長一段時間才能找出最終代碼。我將我的結果放在這裏供將來參考。 (我簡化了代碼一點點這裏闡述的目的,但主要結構應該是正確的。)
content.js:(點擊一個鏈接,打開選項頁)
$("#options").click(function(){
self.port.emit("open_options", {});
});
background.js :
//regsiter the event
backgroundInit = function(worker) {
worker.port.on("open_options", function(request){
var tabs = require("sdk/tabs");
tabs.open({
//open a new tab to display options page
url: self.data.url("options.html"),
});
}
worker.port.on("pull_preferences", function(request){
var preferences = null;
//get preferences (from simple storage or API)
woker.emit("update_content_preferences", {preferences:preferences});
});
worker.port.on("push_preferences", function(request){
var preferences = request.preferences;
//write the preferences (to simple storage or API)
});
}
//register the page, note that you could register multiple ones
pageMod.PageMod({
include: self.data.url('options.html'),
contentScriptFile: [ self.data.url("lib/jquery-1.11.3.min.js"),
self.data.url("options.js")],
contentScriptWhen: 'end',
onAttach: backgroundInit
});
options.js:(此頁還對內容的腳本上下文)
$(document).ready(function(){
self.port.on("update_content_preferences", function(request){
var preferences = request.preferences;
//update options page values using the preferences
});
$("#save").click(function(){
var preferences = null;
//get preferences from options page
self.port.emit("push_preferences", {preferences:preferences});
});
self.port.emit("pull_preferences", {}); //trigger the pull upon page start
});
參考: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
好吧,使用simple-prefs模塊。工作正常,謝謝你! – dvcrn 2012-02-08 19:04:34
謝謝@Wladimir ..不錯的貼子.. – pratikabu 2012-11-06 19:59:57
終於我完成了你說的很好的實現。我肯定會發布我所做的工作示例..感謝提示.. – pratikabu 2012-11-07 13:02:31