javascript - 安全错误 : DOM Exception 18 when invoking toDataURL method of the Canvas

标签 javascript html internet-explorer safari mobile-safari

我在 Internet Explorer 和 Safari 浏览器上尝试从绘制了 SVG 图像的 Canvas 检索数据 URL 时遇到以下错误,而其他浏览器正常工作。

此外,SVG 图像包含一些 <image> xlink:href 的元素属性设置为从用户文件系统读取的图像作为数据 URL。由于这些图像不位于不同的域中,我想不出在尝试获取绘制 SVG 图像的 Canvas 的 dataURL 时抛出此错误的任何原因。提前致谢。

SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent."

最佳答案

我可以使用我制作的测试用例在 Internet Explorer 11 中确认此问题:
http://jsfiddle.net/tsbXW/

这是 Microsoft 正在解决的 Internet Explorer 已知限制:
https://connect.microsoft.com/IE/feedback/details/828416/cavas-todataurl-method-doesnt-work-after-draw-svg-file-to-canvas

如错误报告所示,绘制到 Canvas 中的任何 SVG 图像都会污染 Canvas ,从而在调用 toDataURL() 时导致SecurityError

就其值(value)而言,错误报告的 test case在 Safari 7.0.5 中也不起作用(尽管据称 Apple 已在 Safari 8 中修复了该问题)。此外,由于 Bug 672013 - Allow SVG-as-an-image to be drawn into a canvas without marking it as write-only,该测试用例直到版本 11 才在 Firefox 中运行。 .

关于javascript - 安全错误 : DOM Exception 18 when invoking toDataURL method of the Canvas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21829799/

相关文章:

javascript - 如何比较具有不同字段的 2 个不同对象,并使用告诉共同元素的新字段创建一个新对象

html - 如何解决以下代码中的颜色变化

css - ie/chrome 中的 formalize.css 按钮

html - IE7 仅在来自生产服务器的页面上忽略 CSS 属性选择器

javascript - JS 切换可见性 : How to Hide Already Visible Elements on Click

javascript - TinyMCE 将原始 html 插入事件编辑器

javascript - 变量范围(module.exports + socket.io 设置)

java - Htmlunit中点击按钮后如何刷新页面

JavaScript 宽度检查以禁用事件

internet-explorer - IE 11 开发人员工具不显示元素的宽度