Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 具有任意js的引导加载项创建选项按钮_Javascript_Firefox Addon_Options - Fatal编程技术网

Javascript 具有任意js的引导加载项创建选项按钮

Javascript 具有任意js的引导加载项创建选项按钮,javascript,firefox-addon,options,Javascript,Firefox Addon,Options,我从Bugzilla中了解到,您可以将install.rdf中的选项url设置为任意js,它将运行得非常好。唯一的问题是窗口被禁用,它就像一个不可见的对话框在它上面打开一样,无论你做什么都不能关闭它 例如: 在我的插件中:简单的测试用例,启动时它只会提醒启动,在插件管理器中它会显示选项按钮,单击它会执行一个notifyObserver,但随后它会进入所有对话框模式: 您可以直接从repo安装此加载项 我的选项URL中的代码: <em:optionsURL> javascri

我从Bugzilla中了解到,您可以将install.rdf中的选项url设置为任意js,它将运行得非常好。唯一的问题是窗口被禁用,它就像一个不可见的对话框在它上面打开一样,无论你做什么都不能关闭它

例如: 在我的插件中:简单的测试用例,启动时它只会提醒启动,在插件管理器中它会显示选项按钮,单击它会执行一个
notifyObserver
,但随后它会进入所有对话框模式:

您可以直接从repo安装此加载项

我的选项URL中的代码:

<em:optionsURL>
    javascript:Components.utils.import('resource://gre/modules/Services.jsm');Services.obs.notifyObservers(window, 'hellothisisyourcaptainspeaking', 'options')
</em:optionsURL>

这可以在这里的提交中看到:

您不能阻止加载项管理器打开模式对话框。您可以轻松地关闭它,只需将
window.close()
添加到您的命令中即可。这假设您的代码是在该模式对话框的上下文中运行的——如果不是,那么应该这样做


但是,我认为使用<代码> JavaScript:URL这里很尴尬,这种方法也可能在未来中断。您应该考虑使用一个最小的XUL对话框(没有任何样式表,因此它也将是不可见的),其中包含一个JavaScript文件。然后,您将把代码放在一个合适的脚本文件中,而不是在

install.rdf

中将其压缩到一行中。噢,我没有意识到代码是在对话框中运行的。这两种方法
window.close()
Services.wm…
都非常有效。感谢您推荐使用该文件。
        javascript:
        Components.utils.import('resource://gre/modules/Services.jsm');
        Services.obs.notifyObservers(window, 'hellothisisyourcaptainspeaking', 'options');
        var DOMWin =    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation).QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);
        var utils = DOMWin.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
        utils.leaveModalState();