I want to create an undo button for my web application using javascript. Can someone please help. Basically i got an web app which has got features such as Drawing, Image effect, and Drag and Drop. These functionality are performed on one canvas. All i need is an #Undo button so that if i do a mistake i can go one step backwards. I cant use Jquery. I am looking for a pure javascript to implement that function.
-
1Implementing undo in a web app.Vucko– Vucko2013-05-15 14:04:08 +00:00Commented May 15, 2013 at 14:04
-
1Welcome to stackoverflow! Take a look at this: mattgemmell.com/2008/12/08/what-have-you-triedSteve H.– Steve H.2013-05-15 14:06:15 +00:00Commented May 15, 2013 at 14:06
-
Try rewrite your question in a more detailed way. Clarify the problems that you are with and show your attempts in solve them.Gustavo Carvalho– Gustavo Carvalho2013-05-15 14:33:35 +00:00Commented May 15, 2013 at 14:33
2 Answers
You haven't given much info, so I'll make assumptions.
Assumption 1: all you user drawing interactions are recorded in an array.
If this is true then simply clear the canvas and redraw the interactions from the array tointeractionArray.length -1;Assumption 2: You're using multiple canvas.
If this is true, hide/remove the last (most top) canvas element.
If you're not using either of these methods, maybe look into these methods. Or give us more information on the the method you're currently using.
Note: There are certainly not the only methods to including an "undo" feature!)
1 Comment
Depends on your web application, but shouldn't this do?
<button type="reset">Click Me!</button>
or in js:
<a href="javascript:document.Testform.reset()">Reset Form</a>