Skip to content

Instantly share code, notes, and snippets.

@cgack
Created August 25, 2011 02:30
Show Gist options
  • Save cgack/1169831 to your computer and use it in GitHub Desktop.
Save cgack/1169831 to your computer and use it in GitHub Desktop.
store history and local storage ex
// store the canvas image and push to local storage
var storeHistory = function () {
img = canvas.toDataURL("image/png");
history.pushState({ imageData: img }, "", window.location.href);
if (window.localStorage) { localStorage.curImg = img; }
};
//retrieve local storage
if (window.localStorage) {
var img = new Image();
$(img).load(function () {
canvas.getContext("2d").drawImage(img, 0, 0);
});
if (localStorage.curImg) {
img.src = localStorage.curImg;
}
}
//do history moves
var undo = function () {
window.history.back();
};
var redo = function () {
window.history.forward();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment