Not working in Firefox or IE
I've got things working for several d3 generated svgs but it only works in Chrome. After some debugging I'm finding that the callbacks are not being fired in IE (11) or Firefox (43.0.4) on Windows. For example, I am calling download which calls toImg and passes in a callback function but that callback function never fires. This is true for all of the callbacks. I have attempted to set breakpoints in dev tools and also added some console.logs in the callbacks that confirmed this.
I will continue to do debug and if I come up with a fix I'll do what I can to implement it. Meantime, any thoughts here?
I believe I have worked this out and will document in case anyone else has this issue.
IE simply doesn't support the download attribute which is what is used here. http://caniuse.com/#feat=download
Firefox required that I insert the anchor link into the dom before it would fire the download. Perhaps there's a more elegant solution but adding this to the download function before triggering the click event worked for me (not setting text ensures it isn't visible):
a.href = img.getAttribute('src');
// added this line
document.getElementById("idOfElement").appendChild(a);
a.click();
Thanks @brightrain. I've added support for this Firefox workaround in the latest code. I don't have an IE machine on hand to test, but will take a look when I do.