IE 10:SCRIPT5:锚点点击事件上的访问被拒绝错误
我正在尝试使用 javascript 将画布中的 SVG 保存为 PNG 文件.以下代码似乎在 Chrome 和 Firefox 上运行良好,但在 IE 10 中,我在控制台中收到以下错误.
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:访问被拒绝.
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.
推荐答案
download
属性未在 Internet Explorer 中实现.
The download
attribute is not implemented in Internet Explorer.
http://caniuse.com/download
对于 Internet Explorer,您可以使用另存为"命令.
For Internet explorer you can use the "SaveAs" command.
关于安全性的说明:
浏览器服务于 2 个主机.
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).
使用 a[0].click();
为用户确认运行与浏览器提供安全性的尝试相反.
Using a[0].click();
to confirm for the user runs contrary to the browser's attempt to provide security.
FileSave.js 是一个跨浏览器库,可将您的画布保存到用户本地驱动器.它通过要求用户单击按钮来确定下载来符合安全问题.
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/
相关文章