I am currently creating an app as a side project using jQuery Mobile & PhoneGap. This app will show multiple images and gives the user the opportunity to favorite an image that he/she likes. Once the user clicks on the button to favorite the image, that image will display on the favorites page (favorite.html). I am having trouble using local Storage to incorporate this task. Is it even possible to store and retrieve images to another page? Any help will be great. Below is a link to my jsfiddle if you need a visual.
<!-- Page One -->
<div data-role="page" id="one">
<div data-role="header">
<h1>Page 1</h1>
</div>
<div data-role="main">
<img src="https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg" style="width: 100px;"/>
<br />
<button id="favcat">Click Here to Favorite Cat Image!</button>
<br />
<br />
<img src="http://www.dogslovewagtime.com/wp-content/uploads/2015/07/Dog-Pictures.jpg" style="width: 100px;" />
<br />
<button id="favdog">Click Here to Favorite Dog Image!</button>
</div>
</div>
<!--Page Two -->
<div data-role="page" id="two">
<div data-role="header">
<h1>Page 2: Stored and Retrieved Images Display On This Page Once Clicked</h1>
</div>
<div data-role="main">
</div>
</div>
First you must identify what image should be stored, you can see a custom attribute for image called data-name and other for button called data-image, both have the same content:
Now, when a user click on a image button, first you must get your image:
After you should get the image base64 string
And now save it on localStorage:
And now restore on page two - page two HTML:
Page two JavaScript: