为什么我的init()函数没有运行?(安装Firefox扩展程序时自动添加工具栏按钮,但仅在首次运行时)

 我是赵晓霆 发布于 2023-02-12 16:57

我继续回到这个问题,并继续以失败告终。

我已经阅读了数十页的说明,并查看了诸如“ 如何使Firefox扩展工具栏按钮自动出现?”之类的答案。在这里,但我做对了。

我了解我需要做的事情的概念,但是我要指出的是,虽然扩展本身可以正常工作,但是我无法init(运行)函数,并且似乎也未添加任何负载侦听器(I alertwindow.top.addEventListener..代码之前和之后添加了s,但alerts均未触发。

我想要实现的是建议的过程,即在安装/更新时添加工具栏按钮,但仅在首次运行/安装时添加。

我的扩展包括:

chrome.manifestinstall.rdf在扩展根目录中。

一个chrome包含其它元素的文件夹(extensionName.jsextensionName.pngextensionName.xulextensionName.cssicon.png)。

prefs.jsdefaults/preferences目录中。这包含extensions.MyExtensionNameButton.firstRunDone设置为的首选项false

该扩展本身可以完全按要求运行(它包括一个工具栏按钮和右键单击上下文菜单项)。

我的extensionName.js文件包含以下内容(实际的扩展功能在工作时会被修剪掉,并且可能会使问题变得太长):

objMyExtensionNameButton = {

    // functions that are called by the .xul are in here,


    init : function() {
      var firstRunPref = "extensions.MyExtensionNameButton.firstRunDone";
      alert("init function run");
      if (!Application.prefs.getValue(firstRunPref)) {
        Application.prefs.setValue(firstRunPref, true);
        // all the rest of the first run code goes here.
        alert("this is the first run");
      } else {
        alert("this is NOT the first run");
      }
   }  
};

window.top.addEventListener("load", function() { objMyExtensionNameButton.init(); }, false);

xul包含.js文件的相关部分如下所示:








        
        
    
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有