本文介绍了如何使用Firefox Addon Builder记录选定的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经跟着几个教程没有成功。我认为这是一个典型的例子,但我不能使它工作。我可以保存我的项目,安装插件,当我选择一些文本,我可以看到上下文菜单项日志选择,但是当我点击它时,什么也没有发生。

  

您不能使用 alert 直接在一个lib /模块中。没有窗口可以显示警报,因此没有 alert 函数。



查看。



如果你真的想显示一些东西,你可以使用或 alert 使用 nsIPromptService (例如),或者从一个内容文件(widget等等)。



这里是一个展示不同方法的例子 a>。


I have followed several tutorials with no success. I think this is the classic example but I can't make it work. I can save my project, install the addon and I can see the context menu item "Log Selection" when I select some text, but when I click on it nothing happens.

exports.main = function() {

    var contextMenu = require("context-menu");
    var request = require("request");
    var selection = require("selection");

    var menuItem = contextMenu.Item({
        label: "Log Selection",
        context: contextMenu.SelectionContext(),
        contentScript: 'self.on("click", function () {' +
                 '  var text = window.getSelection().toString();' +
                 '  self.postMessage(text);' +
                 '});',
        onMessage: function (selectionText) {
            alert(selectionText);
        }
    });
}

Even if my addon contains only one alert, the addon is installed but the alert is not shown.

exports.main = function() {
       alert("Hello world");
}

Extra info:

解决方案

You cannot use alert directly in a lib/ module. There is simply no window that could display the alert and hence there is no alert function.

Have a look instead at the Logging documentation.

Should you really want to display something, you could e.g. use notifications, or alert using nsIPromptService (example on this page) or from within a content document (widget, etc).

Here is an example showing off different methods.

这篇关于如何使用Firefox Addon Builder记录选定的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 20:47