简体   繁体   English

每次页面加载时,firefox附加访问变量

[英]firefox add-on access variable everytime page is loaded

I am writing firefox add-on but I have no idea how to do this (how to store variables between page openings): When I open page and if var page_count does not exist, I want to create it and set to 1. If I open another page it should count page_count++ 我正在编写firefox附加组件,但不知道如何执行此操作(如何在打开页面之间存储变量):打开页面时,如果var page_count不存在,则要创建它并将其设置为1。打开另一个页面,它应该计算为page_count ++

I don't know how to set "global" variable in addon (and how to access it later) - it should keep alive between page openings. 我不知道如何在插件中设置“全局”变量(以及以后如何使用它)-它应该在页面打开之间保持有效。 Any idea please? 有什么想法吗?

Maybe you should try to use the Simple Storage to store this variables? 也许您应该尝试使用简单存储来存储此变量? It's pretty simple and (probably) fast. 这非常简单,而且(可能)很快。

https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/simple-storage https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/simple-storage

 var simpleStorage = require("sdk/simple-storage");
 var tabs = require("sdk/tabs");
 simpleStorage.storage.pageCount = 1; //you need to initialize a variable
 tabs.on('open', function onOpen(tab) {
     simpleStorage.storage.pageCount++; //in method
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM