在火狐和Chrome浏览器中,这个链接属性"download=img.jpg“运行良好,并显示下载窗口,而不是新的选项卡或页面。
<a href="img.jpg" download="img.jpg">Download Image</a>
但是在Safari和IE中,这个链接给了我一个新的页面。
那么,在Safari和IE浏览器中处理这个问题的简单而有效的工作流程是什么呢?
发布于 2016-03-08 02:13:41
这是在IE中用JavaScript实现的一种方法。然而,我还找不到Safari的解决方案
var canvas = document.createElement('canvas');
var img = document.createElement('img');
img.onload = function(e) {
canvas.width = img.width;
canvas.height = img.height;
var context = canvas.getContext('2d');
context.drawImage( img, 0, 0, img.width, img.height);
window.navigator.msSaveBlob(canvas.msToBlob(),'image.jpg');
}
img.src = 'img.jpg;
发布于 2015-02-23 18:01:20
navigator.msSaveBlob(blob, filename)
https://msdn.microsoft.com/sv-se/library/windows/apps/hh772331
不幸的是,我不知道如何在Safari中做到这一点。
https://stackoverflow.com/questions/18578473
复制相似问题