Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It can be achieved using <code>The HTML5 FileReader API</code></p> <p>Using only JavaScript and the FileReader object, we can allow the user to load images into an application.</p> <p>HTML code:</p> <pre><code>&lt;input type="file" id="getimage"&gt; &lt;fieldset&gt; &lt;legend&gt;Your image here&lt;/legend&gt; &lt;div id="imgstore"&gt;&lt;/div&gt; &lt;/fieldset&gt; </code></pre> <p>JavaScript code:</p> <pre><code>&lt;script&gt; function imageHandler(e2) { var store = document.getElementById('imgstore'); store.innerHTML='&lt;img src="' + e2.target.result +'"&gt;'; } function loadimage(e1) { var filename = e1.target.files[0]; var fr = new FileReader(); fr.onload = imageHandler; fr.readAsDataURL(filename); } window.onload=function() { var x = document.getElementById("filebrowsed"); x.addEventListener('change', readfile, false); var y = document.getElementById("getimage"); y.addEventListener('change', loadimage, false); } &lt;/script&gt; </code></pre> <p>How To Check If Browser Supports HTML5 File API: </p> <pre><code>// Checking all the possible window objects needed for file api if (window.File &amp;&amp; window.FileReader &amp;&amp; window.FileList &amp;&amp; window.Blob) { // Browser is fully supportive. } else { // Browser not supported. Try normal file upload } </code></pre> <p>Useful ref links below:</p> <p><a href="http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api" rel="nofollow">Demo Here</a></p> <p><a href="http://blog.teamtreehouse.com/reading-files-using-the-html5-filereader-api" rel="nofollow">Complete Example Here</a></p> <p><a href="http://caniuse.com/#feat=filereader" rel="nofollow">Compatibility tables for support of HTML5, CSS3, SVG and more in desktop and mobile browsers</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload