Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to save a SVG from a canvas as PNG file using javascript. The below code seems to work fine on Chrome and Firefox, but in IE 10 i get the below error in my console.

SCRIPT5: Access is denied.

FInd below the code that I've used:

var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");

var a = $('<a>').attr("href", canvas.toDataURL("image/png")).attr("download", title + "png").appendTo($('#VisitsContainer'));

a[0].click();
a.remove();

The console points to the click event that I'm trying to invoke.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
436 views
Welcome To Ask or Share your Answers For Others

1 Answer

The download attribute is not implemented in Internet Explorer.

http://caniuse.com/download

For Internet explorer you can use the "SaveAs" command.

A note about security:

Browsers serve 2 masters.

Browsers must serve the user's request to save content to their local drive.

Browsers must also restrict potentially malicious code from automatically downloading bits onto the users local drive.

To reconcile the 2 tasks, browsers take the approach that users can download content to their local drive after some confirming process (like a Save button).

Using a[0].click(); to confirm for the user runs contrary to the browser's attempt to provide security.

FileSave.js is a cross-browser library that will save your canvas to the users local drive. It conforms to security issues by requiring the user to click a button to OK the download.

https://github.com/eligrey/FileSaver.js/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...