Home > front end >  H5 or JavaScript. How to read the local TXT file? Don't use the file label, directly according
H5 or JavaScript. How to read the local TXT file? Don't use the file label, directly according

Time:09-23

Want to make a small program, h5 can run in mobile phones and computers, has a simple local data storage capabilities,

Put the TXT file and HTML files under the same folder, according to the relative path to TXT file to read and write TXT file or press line, speaking, reading and writing, I found some literacy TXT code on the net, in dw test inside, some only use ie, other browsers with no, some can't use, the generic code?

CodePudding user response:

The browser for security reasons, do not allow the web access to the user's file system directly,
Unless with input label, or small application platform (such as WeChat) have to provide the corresponding interface,
Data is stored, WeChat wx setStorage, H5 localstorage, with IndexedDB

CodePudding user response:

First of all, the web you understand not enough, the web is a server, something on the server can be read
Secondly, to js you understand enough, js is HTML script, run in the browser environment, close the browser limit

There is no any browser allowed to directly read a local file, even use the plug-in implementation, will be all abandon

CodePudding user response:

Some browsers for safety, prohibit using ajax read the client's file, TXT files in the same folder and HTML files also not line,
TXT file to the subordinates and HTML files to the server,
Or https://www.cnblogs.com/Cxymds/p/6896180.html

CodePudding user response:

TXT file in the same folder and HTML file, that is your TXT file on the server, use AJAX to load in

CodePudding user response:

Actually can change an idea, if you are going to configure some dynamic things, save the file and use it, you can do this operation, to create an HTML file, and then introduce TXT or json class files, modify and operating, don't know what is your specific needs, but this way it helps; Users or administrators can open this file directly to write;
  • Related