I am trying to generate a url for the canvas. Here are the steps I followed:
var can = document.getElementsByTagName("canvas");
var src = can.toDataURL("image/png");
When I tried running the above code on firebug it throws an error :
TypeError: can.toDataURL is not a function
I am running firefox 8 on ubuntu.
getElementsByTagNamereturns aNodeList[docs], not a single element.Simply access the first element of the list:
If you want to get the data URL for each canvas, then you have to iterate over the list. Otherwise, giving the canvas an ID and retrieving the reference with
getElementByIdmight be more convenient.