IE 10:SCRIPT5:锚定点击事件时访问被拒绝错误 [英] IE 10: SCRIPT5: Access is Denied error on anchor click event

查看:146
本文介绍了IE 10:SCRIPT5:锚定点击事件时访问被拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用javascript将画布中的SVG保存为PNG文件。
下面的代码似乎在Chrome和Firefox上工作正常,但在IE 10中,我在控制台中得到了以下错误。



SCRIPT5:访问被拒绝。



在我用过的代码下面找到:

  var image = canvas.toDataURL(image / png)。replace(image / png,image / octet-stream); 
$ b var a = $('< a>')。attr(href,canvas.toDataURL(image / png))。attr(download,title +png ).appendTo($( '#VisitsContainer'));

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

控制台指向我试图调用的点击事件。

解决方案

$ 下载属性未在Internet Explorer中实现。

http://caniuse.com/download



对于Internet Explorer,您可以使用SaveAs命令。



关于安全性的说明:

浏览器为2位主人提供服务。

浏览器必须满足用户的请求,才能将内容保存到本地驱动器。

浏览器还必须限制潜在的恶意代码自动将位下载到用户本地驱动器。



为了协调这两项任务,浏览器采取了一种方法,即用户可以在确认过程(如保存按钮)后将内容下载到本地驱动器。 b
$ b

使用 a [0] .click(); 确认用户运行与浏览器提供安全性的尝试相反。



FileSave.js是一个跨浏览器库,可将画布保存到用户本地驱动器。它通过要求用户单击按钮以确定下载来符合安全问题。



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


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.

解决方案

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/

这篇关于IE 10:SCRIPT5:锚定点击事件时访问被拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆