Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save an image to localStorage and display it on the next page?
    primarykey
    data
    text
    <p>So, basically, I need to upload a single image, save it to localStorage, then display it on the next page.</p> <p>Currently, I have my HTML file upload:</p> <pre><code>&lt;input type='file' id="uploadBannerImage" onchange="readURL(this);" /&gt; </code></pre> <p>Which uses this function to display the image on the page</p> <pre><code>function readURL(input) { document.getElementById("bannerImg").style.display = "block"; if (input.files &amp;&amp; input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { document.getElementById('bannerImg').src = e.target.result; } reader.readAsDataURL(input.files[0]); } } </code></pre> <p>The image is displayed instantly on the page for the user to see. They are then asked to fill out the rest of the form. This part is working perfectly.</p> <p>Once the form is complete, they then press a 'Save' button. Once this button is pressed, I save all form inputs as <code>localStorage</code> strings. I need a way to also save the image as a <code>localStorage</code> item.</p> <p>The save button will also direct them to a new page. This new page will display the users data in a table, with the image being at the top.</p> <p>So plain and simple, I need to save the image in <code>localStorage</code> once the 'Save' button is pressed, and then loan the image on the next page from <code>localStorage</code>.</p> <p>I found some solutions such as <a href="http://jsfiddle.net/8V9w6/" rel="nofollow noreferrer">this fiddle</a> and <a href="https://hacks.mozilla.org/2012/02/saving-images-and-files-in-localstorage/" rel="nofollow noreferrer">this article at moz://a HACKS</a>.</p> <p>Although I am still extremely confused on how this works, and I only really need a simple solution. Basically, I just need to find the image via <code>getElementByID</code> once the 'Save' button is pressed, and then process and save the image.</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.
 

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