Tainted canvases may not be exported(受污染的画布不得出口)
问题描述
我想将我的画布保存到 img
.我有这个功能:
I want to save my canvas to a img
. I have this function:
function save() {
document.getElementById("canvasimg").style.border = "2px solid";
var dataURL = canvas.toDataURL();
document.getElementById("canvasimg").src = dataURL;
document.getElementById("canvasimg").style.display = "inline";
}
它给了我错误:
未捕获的安全错误:无法在HTMLCanvasElement"上执行toDataURL":可能无法导出受污染的画布.
Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
我该怎么办?
推荐答案
出于安全原因,您的本地驱动器被声明为其他域";并且会污染画布.
For security reasons, your local drive is declared to be "other-domain" and will taint the canvas.
(那是因为您最敏感的信息可能在您的本地驱动器上!).
(That's because your most sensitive info is likely on your local drive!).
在测试时尝试以下解决方法:
While testing try these workarounds:
将所有与页面相关的文件(.html、.jpg、.js、.css 等)放在桌面上(而不是放在子文件夹中).
Put all page related files (.html, .jpg, .js, .css, etc) on your desktop (not in sub-folders).
将您的图片发布到支持跨域共享的网站(如 dropbox.com 或 GitHub).确保将图像放在 Dropbox 的公用文件夹中,并在下载图像时设置交叉源标志 (var img=new Image(); img.crossOrigin="anonymous"
...)
Post your images to a site that supports cross-domain sharing (like dropbox.com or GitHub). Be sure you put your images in dropbox's public folder and also set the cross origin flag when downloading the image (var img=new Image(); img.crossOrigin="anonymous"
...)
在您的开发计算机上安装网络服务器(IIS 和 PHP 网络服务器都有免费版本,可以很好地在本地计算机上运行).
Install a webserver on your development computer (IIS and PHP web servers both have free editions that work nicely on a local computer).
这篇关于受污染的画布不得出口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:受污染的画布不得出口


基础教程推荐
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01