JavaScript will add a local operation API to operate on local files directly

Source: Internet
Author: User

Chrome, IE, and Firefox all enhance the execution efficiency of the JavaScript engine in the new version. As the JavaScript efficiency increases significantly in various browsers, JavaScript can do more and more things, the introduction of the local file API will make many interesting functions a reality.

A few days ago, Mozilla submitted a draft to W3C to launch a JavaScript API that allows JavaScript scripts to directly operate on local files. Firefox's latest browser version already provides a lot of support for this API, however, for security reasons, this API will only provide limited access to local files.

  • The example explains the Javascript easing effect.
  • Detailed description of Array extensions in Javascript
  • Vs JavaScript HTML5 script API Preview
  • 13 Javascript and CSS menus are recommended
  • Exploring Google's JavaScript development tool Closure
This API introduces a FileReader object that can asynchronously load files in the local file system and allow developers to allocate callback functions for events such as loading failure, progress, and loading completion, it provides a method to read text or binary data from a local file and interrupt the operation at any time using an abort method.

The FileReader object makes access to files on the client a reality. users do not have to upload files to the server as before. In fact, IE and Firefox already have some non-standard methods to access local files, but these methods are not standard JavaScript behavior.

The FileReader object does not require special permissions, but for obvious security reasons, direct access to the file path is not allowed. You must combine the regular HTML file object and Click Browse, select a local file, and use the DOM to reference the file and perform operations. This mechanism makes the API relatively safer, because the user's manual participation is required for obtaining any local file.

The following example uses this API to open a local file and display the file content in a div container. We can even add the contentEditable attribute to the div. You can directly edit the file content. However, this API does not provide a method to write the file content back to a local file, so the content you edit cannot be saved.

 

Although adding APIs to JavaScript is not a significant technological revolution, it will expand the horizons of Web applications and allow the Web platform to implement more and more functions.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.