Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Save Image to LocalStorage #62

Closed
lenichols opened this issue Jun 9, 2014 · 5 comments
Closed

How to Save Image to LocalStorage #62

lenichols opened this issue Jun 9, 2014 · 5 comments

Comments

@lenichols
Copy link

Finally got my pad working... its lovely. My question is... how do I get my signature image to set to localStorage? I'd like the base64 image or dataURI to store in local storage. My goal is to export the image into an html page which will be pdf'd. Any help with this would be great.

@szimek
Copy link
Owner

szimek commented Jun 9, 2014

That should be pretty easy:

saveButton.addEventListener("click", function (event) {
  localStorage.setItem('signature', signaturePad.toDataURL());
});

// and later
img.src = localStorage.getItem('signature');

@lenichols
Copy link
Author

Thanks... im getting img.src is not defined. how would i define it?

@szimek
Copy link
Owner

szimek commented Jun 9, 2014

It was just an example. You need to create image element:

var img = document.createElement('img');
img.src = localStorage.getItem('signature');

// Add image to the page
document.body.appendChild(img);

@lenichols
Copy link
Author

nevermind. i created a seperate variable for the image and it worked! thanks a million!

@szimek
Copy link
Owner

szimek commented Jun 9, 2014

You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants