0

I'm trying to develop HTML base editor equipped with browsing local files function. I know basically that is restricted by browser to open local files. However I found out some method doing this activity. using path begin from "localexplorer://" it works perfect for English path name. But when I use Japanese folder name or file name it becomes error. I tried to convert SJIS format that file names but this is not work. Here is code.

[![error[![\]\[1\]][1]][1]][1]url = 'localexplorer:' + event.target.innerText;
            array = str2array(url);
            sjis_array = Encoding.convert(array, "SJIS", "UNICODE");
            sjis= Encoding.codeToString(sjis_array); 
            window.open(url, '_blank');

2 Answers2

0

According to browser security, javascript is only allowed to run in the sandbox, you cannot read or write arbitrary files:

JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the Web. Browser authors minimize this risk using two restrictions. First, scripts run in a sandbox in which they can only perform Web-related actions, not general-purpose programming tasks like creating files.

If the user selects a file via <input type="file">, you could try to read the content of the file through FileReader API, like this case: How to open a local disk file with JavaScript?

If you need to interact with files on the user's local device or a user-accessible network file system, you can try to use the File System Access API. And this must be done in a secure context, and must be called from within a user gesture. You can also read this article to learn more about it:The File System Access API: simplifying access to local files.

Xudong Peng
  • 1,463
  • 1
  • 4
  • 9
  • Actually what I want to do is described in this site see comment 12, I need a open tag link for local files it not requires input type. – 西浦直志 Aug 14 '21 at 14:05
  • Well, if you are using [Local Explorer-File Manager on web browser](https://chrome.google.com/webstore/detail/local-explorer-file-manag/eokekhgpaakbkfkmjjcbffibkencdfkl), it does not work when the path or file name contains Unicode characters. For more details, you could refer to [LOCAL EXPLORER - USER GUIDE](https://www.vnprodev.com/browser-extensions/local-explorer-install.php?thanks#userguide). – Xudong Peng Aug 16 '21 at 07:50
0

Thank you for your response, I solved this issue by Forefox plug in extensions, it seems like chrome did not support this functions even if there is plug in extensions.

  • Please don't add "thank you" as an answer. Instead, **[accept the answer](https://stackoverflow.com/help/accepted-answer)** that you found most helpful. - [From Review](/review/late-answers/29891646) – Sarath Ak Sep 22 '21 at 18:33