Drawing an image onto a canvas after having refreshed the page or redirected the user

henly

New Member
I have a page that allows the user to draw a signature. The signature is posted to the server as a Base64-encoded PNG. When the user returns to the page, I want the previously drawn signature to be displayed in the same canvas. I have the following CoffeeScript:\[code\]$(document).on('page:load ready', -> signature = new Image() signature.src = http://stackoverflow.com/questions/15590267/$('[name="user[signature]"]').val() $('canvas').get(0).getContext('2d').drawImage(signature, 0, 0))\[/code\]This code works fine when the user enters the URL in the browser and navigates to the page, and when the user navigates around on the website. It fails however when:
  • The users refreshes the page by either clicking reload or hitting F5.
  • The user is redirected to the page.
When I put the same code into a \[code\]$(window).load\[/code\], it works as well but it seems to me this should not be necessary since both a reload and a redirect to the same page causes a \[code\]ready\[/code\] event to be fired on the document.I am seeing this behavior using jQuery 1.9.1 and Chrome 25. Am I overlooking an obvious flaw on my code or have I run into a bug with Chrome?
 
Back
Top