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.
Asked
Active
Viewed 3,895 times
-7
-
1[Implementing undo in a web app](http://stackoverflow.com/questions/6386743/implementing-undo-in-a-web-app). – Vucko May 15 '13 at 14:04
-
1Welcome to stackoverflow! Take a look at this: http://mattgemmell.com/2008/12/08/what-have-you-tried/ – Steve H. May 15 '13 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 May 15 '13 at 14:33
2 Answers
2
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!)

Jarrod
- 9,349
- 5
- 58
- 73
-
what a great idea! I originally thought of reverse engineering every button but your idea makes so much more sense, thanks for sharing! – dizad87 Jan 31 '18 at 09:16
1
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>

Sven Rojek
- 5,476
- 2
- 35
- 57
-
i got image effect and drawing inside the canvas so any movement isdone i got to move one step forward – Palak Jain May 15 '13 at 14:22
-
Isn't that what your looking for? [How to clear the canvas for redrawing](http://stackoverflow.com/questions/2142535/how-to-clear-the-canvas-for-redrawing) – Sven Rojek May 15 '13 at 14:26