1

Is it possible to use a relative path for the URL?

changelog.htm is in the same directory as options.xul

Section of 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>

Are there alternatives?

Update:
If I try the following I get an error "NS_ERROR_MALFORMED_URI:" in console

  <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:
I should have mentioned that my testing was on <em:optionsType>2</em:optionsType>, and as explained in the following answer, it does not seem to work.

Makyen
  • 31,849
  • 12
  • 86
  • 121
erosman
  • 7,094
  • 7
  • 27
  • 46

1 Answers1

3

Yes, relative URLs work just fine.

I don't have references, but just tried it from the options dialog for an extension I am working on. The following opened a dialog window just fine when the button was clicked. It used the XUL in the file test.xul which is in same directory as my options.xul file (defined as the options dialog in instal.rdf) :

<button label="test" oncommand="openDialog('test.xul', '',
    'dialog=no, modal=no, resizable=yes, width=500, height=600');"/>

The followin worked when the test.xul file was in the relative location test/test.xul, but did not exist in the directory containing my options.xul:

<button label="test" oncommand="openDialog('test/test.xul', '',
    'dialog=no, modal=no, resizable=yes, width=500, height=600');"/>

Moved from comments:

However, for XUL that is not actually specifying a window using a full URL may be required. If the window was not actually opened by your XUL you do not necessarily know what the current working directory will be. In such cases, using a relative URL path can result in the error NS_ERROR_MALFORMED_URI: and the operation failing. This is definitely true for options dialogs which are displayed within the Add-on Manager (i.e. they do not open their own window). In your install.rdf file the option <em:optionsType>2</em:optionsType> sets your add-on's options to be displayed within the Add-on Manager. The default, <em:optionsType>1</em:optionsType>, results in a new dialog window opening.

Relative URLs do work from within separate windows. For instance, consider the case of your add-on's dialog, which is within the Add-on Manager, opening another dialog window. In that case relative URLs work just fine from within the XUL of the now open dialog window.

Makyen
  • 31,849
  • 12
  • 86
  • 121
  • Thank you... I get an error "NS_ERROR_MALFORMED_URI:" in console – erosman Sep 22 '14 at 05:07
  • 1
    I just tried it again. I separately tried a cut&paste of each of the ones in my answer and it worked just fine w/o complaint in the Browser Console. I also tried it with a basic `.htm` file and it also worked fine. To go further in trying to find out what the problem is in your config we are going to need more information about your configuration (OS, Firefox version, maybe your `options.xul` file, `chrome.manifest`, and `install.rdf`). Is your options.xul working otherwise? Does it work when you use a complete URL? What type of add-on? Is it extracted when testing, or in an .xpi? – Makyen Sep 22 '14 at 05:39
  • I like you man, you give your own take on answers and dont go with just whats out there! – Noitidart Sep 22 '14 at 07:20
  • @Makyen Thank you ... Since I use the same structure in all my addons, just pick any of [my addons](https://addons.mozilla.org/user/azbb/) for an example (pic a simple one) ... Win7 (although not relevant), FF 32.0.2 – erosman Sep 22 '14 at 07:31
  • 2
    I confirm that it does not work here with `2`, but works just fine with [`1`](https://developer.mozilla.org/en-US/Add-ons/Install_Manifests). It appears that the issue is not something generic with XUL, but with XUL that is used for [options displayed within the Add-on Manager](https://developer.mozilla.org/en-US/Add-ons/Inline_Options). My first guess is that the current working directory is not set to what you think it should be. – Makyen Sep 22 '14 at 10:49
  • @Noitidart: Thank you. I like you too. I find your answers quite helpful. -----@erosman: I updated and expanded my answer based on testing with your Text MultiCopy add-on. – Makyen Sep 22 '14 at 11:21
  • Thank you ... if you find a way with optionsType 2, please let me know – erosman Sep 22 '14 at 16:38