HTML5 File API is a W3C standard that allows local file access via web-based JavaScript.
The HTML5 File API reuses the same HTML form field input tag of type ‘file’ previously available in HTML 4.01, but with which it was only possible to upload the file contents to a remote web server rather than directly read the contents locally.
<!-- Including the h5ile toolkit JavaScript file: --> <script type='text/javascript' src='h5ile-release-0.1-src.js'></script>
<div style='display:none;' id='demo_container'> <!-- This div will initially be hidden from view, and only shown if the browser supports HTML5 File API. --> Visible file input: <span id='visible_file_input'></span> <!-- The h5ile toolkit will insert the visible HTML form field file input tag into the span above. --> </div> <div> Loaded file displays here: <pre id='loaded_file_contents' style='border: solid 1px black; overflow: auto;'> </pre> </div>
<!-- This script tag can go right after the HTML markup above. --> <script type='text/javascript'> // <!-- // Check if this browser supports the HTML5 File API: if (h5ile.isFileAPISupported()) { // Have browser support. // This makes the demo container visible. Recommend doing this via // a JavaScript toolkit such as Dojo or jQuery in real life. document.getElementById('demo_container').setAttribute('style', ""); // This function call inserts the visible HTML form field file input // tag into the span with HTML id 'visible_file_input', and loads // the text file: h5ile.createVisibleFileInput( 'visible_file_input', { loadtext: { onloadend: function(file, file_reader) { // Callback function receives HTML5 File API // 'File' and 'FileReader' objects associated with // the file and containing the file contents. var elContents = document.getElementById( 'loaded_file_contents'); elContents.textContent = file_reader.result; } } }); } // --> </script>
Copyright (c) 2010-2018 Marat Nepomnyashy
Except where otherwise noted, this webpage is licensed under a Creative Commons Attribution 3.0 Unported License.
Background wallpaper by Patrick Hoesly, used under Creative Commons Attribution 2.0 Generic License.