我在 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/