javascript - Show Directory Browse Dialog in Firefox Addon -


I want to choose a folder by showing a dialog to my user.

Is this possible with JavaScript in Firefox?

Enter image details here

< Div class = "post-text" itemprop = "text">

Yes, an easy way to do this is to use the common method.

The primary difference from the example on that page is that in the method passed to the parameter init, you specify nsIFilePicker. Mode Gatefolder as mode . Also, given that you are looking for a directory, you can only filter from nsIFilePicker.filterAll , and not.

The example code would like to include a filter for a particular type of extension: MDN page, modified (and descriptive variable names given) to select folders:

  if (window === faucet = window type! == "object") {// If you do not already have any window reference, you need to get one: // your environment To comment on the appropriate version for "/" add / * E-on SDK environment: var window = require ( 'SDK / windows / UTI "). GetMostRecentBrowserWindow (); // * / / * Overlay and bootstrap environment (from almost any reference / scope): var window = Components.classes ["@ mozilla.org/appshell/window-mediator;1"] .getService (Components.interfaces.nsIWindowMediator ) .getMostRecentWindow ("navigator: browser"); // * nosIFilePicker = Components.interfaces.nsIFilePicker; Var filePicker = Components.classes ["@ mozilla.org/filepicker;1"] .createInstance (nsIFilePicker); FilePicker.init (window, "Dialog title", nsIFilePicker.modeGetFolder); FilePicker.appendFilters (nsIFilePicker.filterAll); Var pickerStatus = filePicker.show (); If (PickerStatus == NSifPPP. Thirneoeke) PickerStatus == NSI FileConverter. Change Returns {var file = filePicker.file; // Find the path as string Note that you will not usually need to work with string path // var path = filePicker.file.path; // work with returned nsILocalFile ...}    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -