Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:03:54+00:00 2026-06-06T15:03:54+00:00

here is my page http://www.dev.1over0.com/canvas/canvas_web.html I’m having issues with the undo functionality – I

  • 0

here is my page
http://www.dev.1over0.com/canvas/canvas_web.html

I’m having issues with the undo functionality – I think I’m getting close but here’s the issue

First I’ll tell you the basics of the drawing application – I’m layering four different canvases
http://www.dev.1over0.com/canvas/js/canvas_web.js
if you look at the js file you’ll see at the top all my comments on what I’m doing with the canvases

when a user uses a tool to draw – it actually draws it first temporarily on the imageTemp canvas –
each tool has it’s own object (pencil, rectangle, line)
with functions within for mousedown, mousemove and mouseup events

at the end of the mouseup event it calls this function

function img_update() {
contexto.drawImage(canvas, 0, 0);
saveActions();
context.clearRect(0, 0, canvas.width, canvas.height);
}

Here the image that’s on the temp canvas ends up being drawn on the imageView canvas so essentially the imageTemp canvas is being erased each time

So for the undo functionality I first declare a an empty array

var undoHistory = [];

I also declare a new image

var undoImg = new Image();

when img_update is invoked – it calls another function saveActions

function saveActions() {
var imgData = canvaso.toDataURL("image/png");
undoHistory.push(imgData);
$('#undo_canvas button').removeAttr('disabled');
}

In this function – I’m essentially saving the newly drawed image canvas into the undoHistory array
This seems to be working fine (I believe)
So after each time the permanent imageView canvas is updated is saves that state into an array

Now if you notice once you draw an image and it’s save to the imageView canvas the undo button becomes enabled

So if you click the undo button it calls this function

function undoDraw() {
if(undoHistory.length > 0){ 
$(undoImg).load(function(){
contexto.drawImage(undoImg, 0,0);
 });
undoImg.src = undoHistory.pop();
if(undoHistory.length == 0) { 
$('#undo_canvas button').attr('disabled','disabled');
}
}
}                              

Here what I’m trying to do is take the previous image state and draw it on the canvas
It’s working in a way that it affects the z-index of the images but not getting rid of the images
And you have to click it twice as well which confuses me

So if you can try drawing out three rectangles on top of each other
You can click the undo button and it will effect the z-index – click it three times you’ll see what I mean so it’s sort of working, maybe ;-{

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:03:55+00:00Added an answer on June 6, 2026 at 3:03 pm

    You have to clear the canvas before you draw the last image, otherwise it will draw an image onto the previous canvas;
    Also, you pop the last image which is the one you just’ve pushed in (this is why you have to click twice). So try something like this ( you might have to adapt the code I’m not sure it works out of the box)

    function undoDraw(){
       if(undoHistory.length > 0){ 
          $(undoImg).load(function(){
              contexto.clearRect(0,0, canvas.width, canvas.height);     
              contexto.drawImage(undoImg, 0,0);
         });
       undoHistory.pop();
       undoImg.src = undoHistory.pop();
       if(undoHistory.length == 0) { 
       $('#undo_canvas button').attr('disabled','disabled');
            }
         }                
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is the test page http://www.studioteknik.com/html/test-portfolio.html I got no error, but no hover-slide effect...
So I have this page here: http://www.eminentmedia.com/development/powercity/ As you can see when you mouse
The page in question is featured here: http://www.allwebcafe.com/news/news-article.php?id=78 For some reason, when a user
I using coda slider in my page. View it here: http://www.ndoherty.com/demos/coda-slider/1.1.1/ Each tab causes
For example, here's a 'page': http://www.facebook.com/facebook That page has an RSS feed (which I'd
I have a print page here: http://www.souq4cars.com/ppreview.php?id=611111161&u=10064&t=users_cars How do i hide the links at
I have a test page here: http://www.problemio.com/test.php and if you press Click To Test
I have a basic web page here http://www.webdevout.net/test?0V , reproduced below <!DOCTYPE html PUBLIC
Was looking at the reference page here : http://www.w3.org/TR/html5/offline.html I copied and pasted the
I am using jQuery UI for the sidebar navigation here: http://www.imadesign.com/dev/work/ I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.