This solution will work if the element you want to bind the click event to already exists:
var url = canvas.toDataURL();
var link = document.getElementById('-insert a element id here');
link.download = "DownloadName";
link.href = url;
This will create the data url, then assign it to the href of whatever link you have if it already exists, you just need to replace '-insert a element id here' with the id of the link you want it to be assigned to.
Alternatively if it doesn't exist you could do:
var url = canvas.toDataURL();
var link = document.createElement('a');
link.download = "DownloadName";
link.href = url;
link.innerHTML = "Download";
document.getElementById('-insert parent element here-').appendChild(link);
This will create the data url, then create an a element, set its download, href and innerHTML properties and insert it in the DOM. Just replace '-insert parent element here-' with whatever element you want the link to be inside.