<a id="download" href="link of your file">click here to download the file</a>.
<script>
var downloadTimeout = setTimeout (
function() {
window.location = document.getElementById('download').href;
}, 4000);
</script>
这不是我想要的,我需要将图像自动下载 时间是由setTimeout停止但我无法得到它。请帮我。谢谢
答案 0 :(得分:0)
您可以使用HTML5进行操作。要下载图片,请将download
媒体资源添加到您的链接中。请注意,这在某些浏览器中不起作用。您可以在JSFiddle上试用。
<a href = "yourImage.png" download = "customName.png" id = "download">Click here to download image</a>
<canvas></canvas>
<script>
setTimeout(function(){
downloadCanvas();
}, 4E3);
function downloadImage(){
document.getElementById('download').click();
}
function downloadCanvas(){
var a = document.getElementById('download');
var b = a.href;
a.href = document.getElementsByTagName('canvas')[0].toDataURL();
downloadImage();
a.href = b;
}
</script>