So, basically, I need to upload a single image, save it to localStorage, then display it on the next page.
Currently, I have my HTML file upload:
<input type='file' id="uploadBannerImage" onchange="readURL(this);" />
Which uses this function to display the image on the page
function readURL(input)
{
document.getElementById("bannerImg").style.display = "block";
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById('bannerImg').src = e.target.result;
}
reader.readAsDataURL(input.files[0]);
}
}
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.
Once the form is complete, they then press a 'Save' button. Once this button is pressed, I save all form inputs as localStorage
strings. I need a way to also save the image as a localStorage
item.
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.
So plain and simple, I need to save the image in localStorage
once the 'Save' button is pressed, and then loan the image on the next page from localStorage
.
I found some solutions such as this fiddle and this article at moz://a HACKS.
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 getElementByID
once the 'Save' button is pressed, and then process and save the image.