搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

How to open links to filesystem folders with system file manager.

  • 12 回覆
  • 0 有這個問題
  • 71 次檢視
  • 最近回覆由 cor-el

more options

I have a 'site' that is just files on my hard drive.

I need to click an anchor link such as: <a href="file:///dir1/dir2/dir3/dir4">Store Your Files Here</a> and have Firefox open the folder dir4 with the systems file manager. ( In my case the file manager is Nautilus ) ( Ubuntu 20.04 )

I have seen this: http://kb.mozillazine.org/Links_to_local_pages_do_not_work but it does not describe a scenario that uses the file:/// interface.

It also does not provide any information about how the files will be handled.

I can get the folder link to work currently , but it appears with the: 'Index of file///...' in a browser tab.

Obviously you can not use that for anything useful.

The main goal is to open the folder and be able to use the system file manager to include more content for the site without having to navigate to the folder manually. The folders I want to display are buried many levels down without the possibility of having descriptive names. I have ~121 pages/folders in this arrangement , and each one has content for each page. I would like to add a button on each of the 121 pages that will open each of the pages content folder.

I have a 'site' that is just files on my hard drive. I need to click an anchor link such as: <a href="file:///dir1/dir2/dir3/dir4">Store Your Files Here</a> and have Firefox open the folder dir4 with the systems file manager. ( In my case the file manager is Nautilus ) ( Ubuntu 20.04 ) I have seen this: http://kb.mozillazine.org/Links_to_local_pages_do_not_work but it does not describe a scenario that uses the file:/// interface. It also does not provide any information about how the files will be handled. I can get the folder link to work currently , but it appears with the: 'Index of file///...' in a browser tab. Obviously you can not use that for anything useful. The main goal is to open the folder and be able to use the system file manager to include more content for the site without having to navigate to the folder manually. The folders I want to display are buried many levels down without the possibility of having descriptive names. I have ~121 pages/folders in this arrangement , and each one has content for each page. I would like to add a button on each of the 121 pages that will open each of the pages content folder.

由 Tyranna 於 修改

所有回覆 (12)

more options

Try using ctl+o to open a file. In the dialogue you can select a folder whereupon you get what is shown in the attached screenshot.


Wouldn't it be simpler to use the file manager? I am not familiar with Nautilus. Does it not provide for bookmarks or split viewing?

more options

No , it would not be easier to use the file manager. That would just make it more inconvenient than it already is by adding several steps in front of self navigating the directory tree. Secondly , the open file ( CTRL-O ) is for opening a file. I am not trying to open a file. I need to view the contents of the directory linked in the anchor-link/button in the file manager .

A good example would be when I add am image to the currently viewed page: There is an anchor-link/button on the page that opens the HTML file. Firefox opens the file in the gedit ( the systems default text editor). This works and is implemented already. My second anchor/button needs to display the 'images' directory. ( This is the function I am asking about ). Then I can drag a image from my desktop directly into the correct directory.

more options

To open links to filesystem folders with the system file manager in Firefox, you can follow these steps:

Type about:config in the Firefox address bar and press Enter. Accept the warning to proceed. In the search bar, enter network.protocol-handler.expose.file. Double-click on the preference to change its value to true. After enabling the network.protocol-handler.expose.file preference, you should be able to open links to filesystem folders using the system file manager. When you click on an anchor link such as <a href="file:///dir1/dir2/dir3/dir4">Store Your Files Here</a>, it should open the folder dir4 with the system file manager (Nautilus in your case).

Please note that when opening file links, Firefox will display the "Index of file://" page by default, showing the directory listing. This is the expected behavior and cannot be changed. However, you can ignore that page and focus on using the system file manager to navigate and manage the content of the folder.

If you have any further questions or need additional assistance, feel free to ask in the Firefox Support Forum. Our community members and volunteers will be happy to help you.

more options

I don't think you can reassign how Firefox handles file:/// links.

When I needed to do something similar to this to launch PDFs based on their local path in the file system, I defined a new protocol ("mypdf:") and created a script to execute Acrobat with the file location as a parameter. This works either in a http/https page or in a file page ("mypdf:[localpath]" instead of a file:/// link).

On Windows, the next step was to set up a registry entry for the protocol with a shell command pointed at the script. When confronted with this novel protocol, Firefox found it in the registry and prompted me to use the script.

I don't know how to do these things on Linux, but it might be similar to how users set up magnet: protocol links and then instruct Firefox on their existence.

more options

Actually, I found some leads in an old 2019 thread. Web pages are still restricted from using file:/// links, but if you are in a page that is itself on a file:/// URL, it should work as expected.

(1) In a new tab, type or paste about:config in the address bar and press Enter/Return. Click the button accepting the risk.

More info on about:config: Configuration Editor for Firefox. The moderators would like us to remind you that changes made through this back door aren't fully supported and aren't guaranteed to continue working in the future.

(2) In the search box in the page, type or paste network.protocol-handler.expose.file and pause while the list is filtered

Firefox normally shows the preference name followed by Boolean Number String and a + button. If this preference already exists with a value of true, skip to #4. If it already exists with a value of false, skip to #5.

(3) Keep the selector on Boolean and click the "+" button to create a new preference. By default, the value will get set to true.

(4) Double-click the preference (or click the toggle button toward the right end of the row) to change the value to false for this preference.

(5) In the search box in the page, type or paste network.protocol-handler.external.file and pause while the list is filtered

Firefox normally shows the preference name followed by Boolean Number String and a + button. If this preference already exists with a value of true, you're done. If it already exists with a value of false, skip to #7.

(6) Keep the selector on Boolean and click the "+" button to create a new preference. By default, the value will get set to true.

(7) If the value is set to false, double-click the preference (or click the toggle button toward the right end of the row) to change the value to true for this preference.

Success?

more options

Thank you to suram080 and jscher2000.

The solution works! partially.... ( In my individual case. )

TO: jscher2000: I also do not know how to set up a protocol like that in LINUX either.

Setting the network.protocol-handler.expose.file and network.protocol-handler.external.file values allowed me to open the directory just like I wanted to. YAY But , A different problem has crept in. Along the left side of my page are several links to other .HTML files that are on the file:/// system. It is now popping up a prompt asking what I would like to open them with. I select Firefox from the list , and a new tab opens. The previous and , and desired behavior is to NOT have the prompt and have that new page open in the same tab.

I then tried links that are not on the file:/// system and they do not prompt , and do not open in a new tab. I do not want/need Firefox to prompt me for all links to file:/// .HTML files.

These links are just page selectors. Each page is identical except for the names on a set of tabs and the content in the central frame under them.

Possible solutions?: - I wonder if setting the mime type in preferences->applications might work... - toggling files access on only when clicking on the links to folders. ( seems like

 I would have no direct access to these variables from the browser page. )

- Setting up a policy similar to:

  http://kb.mozillazine.org/Links_to_local_pages_do_not_work

- Rewriting the entire site to not use links to .HTML files on the hard drive ( golden option ;)

QUOTE: Please note that when opening file links, Firefox will display the "Index of file://" page by default, showing the directory listing. This is the expected behavior and cannot be changed. ENDQUOTE: This did not happen when those two flags are set.


Update: For some reason , ( probably because I closed the tab and reopened it ). , I am no longer getting the prompts when opening links to other file:/// based .HTML pages.


To fix the opening in new tab: I added target="_self" to the file:///.HTML links but Firefox still opens a new tab...

So currently :

(+1) links to folders are opening to the proper location. (-1) .HTLM file links are now opening in a new tab.

由 Tyranna 於 修改

more options

With the new preferences set: I can not get the links to not open in another tab.

The original behavior was that the links opened in the same tab. I reset the two preferences and they still open in a new tab. I can not re-establish the original behavior!

Something has changed and I do not know what it is. ( and I did nothing extra ).

I need to stop the file: links opening in new tabs. HELP!

more options

You have file:/// links to web pages, so Firefox sends those to the OS and the OS sends them back. It's normal for externally launched pages to open in a new tab in the active window. While you can change that to replace the active tab in the active window, that could lead to unwanted results when you are following links from other applications. I guess which is the more common scenario?

The relevant preference is browser.link.open_newwindow.override.external which has these options:

  • -1 => new tab or new window, following the setting for links in Firefox
  • 3 = open external links in a new tab in the last active window
  • 2 = open external links in a new window
  • 1 = open external links in the last active tab replacing the current page <= Try this one
more options

Ok , that seems to work. If I understand correctly , what I have done is tell Firefox to handle the 'file' protocol with an external application. But when I do this , the system handles the .file protocol resource with the system handler , and that is Firefox. Therefore Firefox takes the linked file as input , and by default , opens the link in a new tab. And now that we have set browser.link.open_newwindow.override.external value to 1 , ( it was -1 ) , Firefox will no longer open in a new tab , but in the same tab. But , this will cause all other applications using the handler , that WOULD have opened in a new tab , to open in the same tab.

more options

Yes, with that settings change, all external URLs and files sent to Firefox by the system will open in the last active tab rather than a new tab.

The only way I know to resolve this in a way that doesn't have any side effects is to use a novel protocol for the directory links and create a new handler (external to Firefox) for the novel protocol. And then leave everything else at its default behavior.

more options

Thanks for walking me through that process. Your answers were very concise. +1

more options

Note that browser.link.open_newwindow.override.external should be set to 3 for a new tab (1 is current tab).

Normal Links:

  • browser.link.open_newwindow
    1:current tab; 2:new window; 3:new tab;

External Links:

  • browser.link.open_newwindow.override.external (see browser.link.open_newwindow)