是否可以使用URL的相对路径?
changelog.htm
与options.xul
options.xul
<setting title="&options.changelog.title;" type="control">
<button label="&options.changelog.label;"
oncommand="openDialog('chrome://myAddon/content/changelog.htm', '',
'dialog=no, modal=no, resizable=yes, width=500, height=600');"/>
</setting>
有替代方案吗?
更新
如果我尝试以下操作,我会在控制台中收到错误“NS_ERROR_MALFORMED_URI:"
<setting title="&options.changelog.title;" type="control">
<button label="&options.changelog.label;"
oncommand="openDialog('changelog.htm', '',
'dialog=no, modal=no, resizable=yes, width=500, height=600');"/>
</setting>
UPDATE2:
我应该提到我的测试是在<em:optionsType>2</em:optionsType>
,并且如下面的答案中所解释的那样,它似乎不起作用。
答案 0 :(得分:3)
是的,相对URL工作得很好。
我没有引用,但只是从我正在处理的扩展的选项对话框中尝试过它。单击按钮时,以下打开了一个对话框窗口。它在文件test.xul
中使用了XUL,该文件与我的options.xul
文件位于同一目录中(定义为instal.rdf
中的选项对话框):
<button label="test" oncommand="openDialog('test.xul', '',
'dialog=no, modal=no, resizable=yes, width=500, height=600');"/>
当test.xul文件位于相对位置test/test.xul
时,以下内容有效,但在包含options.xul
的目录中不存在:
<button label="test" oncommand="openDialog('test/test.xul', '',
'dialog=no, modal=no, resizable=yes, width=500, height=600');"/>
从评论中移出:
但是,对于实际上未使用完整URL指定窗口的XUL可能是必需的。如果您的XUL实际上没有打开窗口,您不一定知道当前工作目录是什么。在这种情况下,使用相对URL路径可能导致错误NS_ERROR_MALFORMED_URI:
并且操作失败。对于Add-on Manager中显示的选项对话框(即它们不打开自己的窗口),这肯定是正确的。在install.rdf
文件中,选项<em:optionsType>2</em:optionsType>
设置要在加载项管理器中显示的加载项选项。默认值<em:optionsType>1</em:optionsType>
会导致打开一个新的对话框窗口。
相对URL可以在不同的窗口中运行。例如,考虑加载项对话框的情况,该对话框位于加载项管理器中,打开另一个对话框窗口。在这种情况下,相对URL可以在现在打开的对话框窗口的XUL中正常工作。