Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
465 views
in Technique[技术] by (71.8m points)

javascript - IE 10: SCRIPT5: Access is Denied error on anchor click event

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

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

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...