0

Both file are html, index.html and show.html, in index.html i have a very basic form with a single input type="file", when user selects a file(only images) it shows a preview, when user clicks on "send" the user goes to the show page and I want to show on that page the image that was "uploaded", but since no images are uploaded because is just a demo with no actual uploading functions how do I show that image?... the jquery library that I use to preview the image in index.html converts the image in to a base64 code I'm able to get that value, but in show.html I can't use POST, and using ajax is out of the question, i was thinking to use:

document.getElementById("posted_image").innerHTML = window.location.search;

then just parse the value, but the problem is that the base64 code of that image is humongous it wont work... also I was thinking to store the value in a cookie but I don't know how to do that with javascript or if a cookie has a limitation... is there an actual way of doing this without the use of PHP?..

Tanker
  • 1,178
  • 3
  • 16
  • 49
  • you can use localstorage – DK3 May 06 '16 at 19:09
  • You can't only use javascript to accomplish this, you need to save it somewhere first (The image) – Alexandre May 06 '16 at 19:13
  • 1
    Use HTML5 sessionStorage (if the data only needs to persist that session) or HTML5 localStorage (if you need the data to persist beyond the current session.) I use sessionStorage whenever I can in order to avoid possible data conflicts if another site uses the same key names. – Korgrue May 06 '16 at 19:30
  • @Korgrue yes, it is use for that session only, there is no need to extend the use of sessions, I read about sessionStorage just never use it and I totally forgot about them... thanks. – Tanker May 06 '16 at 19:41

1 Answers1

2

first you should convert the image into base64 as you did already so if you have value then use localStorage to store the image

localStorage.setItem("base64mgData",  base64mgData);

here is the stackoverflow link

Community
  • 1
  • 1
DK3
  • 403
  • 2
  • 10
  • I use sessionStorage whenever I can in order to avoid possible conflicts in the global namespace. localStorage is best to avoid unless absolutely necessary - or you MUST remember to kill the storage key at the end of session. – Korgrue May 06 '16 at 19:34