Download canvas to Image in IE using Javascript(使用 Javascript 将画布下载到 IE 中的图像)
问题描述
以下代码会将画布转换为图像,并且在 IE 以外的浏览器中下载相同的内容(我使用的是 IE9).IE 代码在新选项卡中打开 DataURL.但是,它不可下载.
Below code will convert canvas to image and the same is downloaded in browsers other than IE(I'm using IE9).IE Code opens theDataURL in new tab.But,it is not downloadable.
if(navigator.appName == "Microsoft Internet Explorer")
{
somehtml1= document.createElement("img");
somehtml1.id="imgid";somehtml1.name="imgname";
somehtml1.src=canvas.toDataURL("image/png");
document.body.appendChild(somehtml1);
window.win = open (somehtml1.src);
setTimeout('win.document.execCommand("SaveAs")', 500);
}
else
{
somehtml= document.createElement("a");
somehtml.href = canvas.toDataURL("image/png");
somehtml.download = "test.png";
}
推荐答案
这是我正在使用的 - 不确定这需要什么版本的 IE,因为我正在使用 11.它使用 IE 的 blob 和画布作为 dataURL对于其他浏览器.在 Chrome 和 IE 11 中测试.
Here's what I'm using - not sure what version of IE this requires as I'm using 11. It uses a blob for IE and canvas as a dataURL for other browsers. Tested in Chrome and IE 11.
(canvas为画布对象,link为超链接对象)
(canvas is the canvas object, link is an hyperlink object)
if (canvas.msToBlob) { //for IE
var blob = canvas.msToBlob();
window.navigator.msSaveBlob(blob, 'dicomimage.png');
} else {
//other browsers
link.href = canvas.toDataURL();
link.download = "dicomimage.png";
}
这篇关于使用 Javascript 将画布下载到 IE 中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Javascript 将画布下载到 IE 中的图像


- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07