点击链接后强制浏览器保存文件 [英] Force a browser to save file as after clicking link

查看:98
本文介绍了点击链接后强制浏览器保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:


是否有强制浏览器使用JavaScript例程将文件另存为(保存作为)点击链接后?我需要默认直接下载图片,而不是由浏览器呈现。

您可以使用HTML5下载属性所以:

 < a href =路径/ to / file下载>点击此处下载< / a> 

这会打开一个另存为对话框,无论文件类型如何,都不会将您带离页面。 / p>

Possible Duplicate:
Is it possible to initiate a download prompt in the browser for recognized MIME types using only JavaScript (client-side approach)?

Is there a way to force a browser with a JavaScript routine to save a file as ("save as") after clicking a link? I need for images to be downloaded directly by default and not rendered by the browser.

解决方案

You could use the HTML5 download attribute like so:

<a href="path/to/file" download>Click here to download</a>

This opens a "save as" dialog regardless of file type without taking you away from the page.

这篇关于点击链接后强制浏览器保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆