尝试下载画布时与 IE 的兼容性问题
Compatibility problems with IE when trying to download canvas
我在使用 Internet Explorer 和 Canvas 时遇到问题。当我在任何其他浏览器中测试它时,它都有效。只是 IE 使我感到不适。
这是我的 Javascript 函数实现的地方。
<script type="text/javascript">
var szorientation;
szorientation="l";
/*****************************************************************
* This is the function that will take care of image extracting and
* setting proper filename for the download.
* IMPORTANT: Call it from within a onclick event.
*****************************************************************/
function downloadCanvas(link, canvasId, filename) {
link.href = document.getElementById(canvasId).toDataURL("image/jpeg");
link.download = filename;
}
function begin(){
initcanvas();
}
</script>
这是它被调用的地方。我哪里错了?
<script>
//Download image to user
document.getElementById('myalink').addEventListener('click', function() {
downloadCanvas(this, 'memcanvas', 'mypic.jpg');
}, false);
var imageLoader = document.getElementById('imageLoader');
imageLoader.addEventListener('change', handleImage, false);
document.addEventListener('DOMContentLoaded',domloaded,false);
function domloaded(){
// your code here.
begin();
}
</script>
提前致谢!
IE 尚不支持 download
属性,因此您的代码无法在 IE 中运行。
您可以使用 Eli Gray 的这个很棒的解决方法让 IE 用户将您的 canvas 下载到他们的本地驱动器:
https://github.com/eligrey/FileSaver.js
或者您可以去 "old-school" 并在另一个浏览器选项卡中将 canvas.toDataURL
作为图像打开,然后让您的用户 'right-click-save-as' 该图像。
我在使用 Internet Explorer 和 Canvas 时遇到问题。当我在任何其他浏览器中测试它时,它都有效。只是 IE 使我感到不适。 这是我的 Javascript 函数实现的地方。
<script type="text/javascript">
var szorientation;
szorientation="l";
/*****************************************************************
* This is the function that will take care of image extracting and
* setting proper filename for the download.
* IMPORTANT: Call it from within a onclick event.
*****************************************************************/
function downloadCanvas(link, canvasId, filename) {
link.href = document.getElementById(canvasId).toDataURL("image/jpeg");
link.download = filename;
}
function begin(){
initcanvas();
}
</script>
这是它被调用的地方。我哪里错了?
<script>
//Download image to user
document.getElementById('myalink').addEventListener('click', function() {
downloadCanvas(this, 'memcanvas', 'mypic.jpg');
}, false);
var imageLoader = document.getElementById('imageLoader');
imageLoader.addEventListener('change', handleImage, false);
document.addEventListener('DOMContentLoaded',domloaded,false);
function domloaded(){
// your code here.
begin();
}
</script>
提前致谢!
IE 尚不支持 download
属性,因此您的代码无法在 IE 中运行。
您可以使用 Eli Gray 的这个很棒的解决方法让 IE 用户将您的 canvas 下载到他们的本地驱动器:
https://github.com/eligrey/FileSaver.js
或者您可以去 "old-school" 并在另一个浏览器选项卡中将 canvas.toDataURL
作为图像打开,然后让您的用户 'right-click-save-as' 该图像。