Cảm ơn Wladimir Palant
để chỉ ra hướng, tuy nhiên nó vẫn đưa tôi nhiều thời gian để tìm ra các mã cuối cùng. Tôi đặt kết quả của tôi ở đây để tham khảo những người khác trong tương lai. (Tôi đơn giản hóa mã một chút ở đây cho mục đích xây dựng, nhưng cơ cấu chính nên chính xác.)
content.js: (bấm vào một liên kết để mở trang tùy chọn)
$("#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: (trang này cũng là bối cảnh nội dung kịch bản)
$(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
});
Tham chiếu: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/tabs
Nguồn
2016-02-08 10:06:22
Được rồi, sử dụng mô-đun prefs đơn giản. Hoạt động tốt, cảm ơn cho điều đó! – dvcrn
cảm ơn @Wladimir .. tốt đẹp đăng .. – pratikabu
cuối cùng tôi đã hoàn thành một thực hiện tốt đẹp của những gì bạn nói. Tôi chắc chắn sẽ gửi mẫu làm việc của những gì tôi đã làm .. cảm ơn cho các gợi ý .. – pratikabu