HTMLCanvasElement does not have a 'toDataUrl' method

I am trying to extract dataUrl from a canvas in order to use it as a css background-image for various elements. But I always get the following Uncaught TypeError: Object #<HTMLCanvasElement> has no method 'toDataUrl' error Uncaught TypeError: Object #<HTMLCanvasElement> has no method 'toDataUrl'

this is my test code

 <!DOCTYPE html> <html> <body> <canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;"> Your browser does not support the canvas element. </canvas> <script type="text/javascript"> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.fillStyle="#FF0000"; ctx.fillRect(0,0,150,75); alert(c.toDataUrl()); </script> </body> </html> 

is it again a security feature in disguise ?, or am I just stupid ...

Thanks in advance

+7
source share
1 answer

You have the wrong function name. Look at the case:

 alert(c.toData URL ()); 

Demo

+19
source

All Articles