码迷,mamicode.com
首页 > 其他好文 > 详细

点击链接不在浏览器打开而是弹出下载对话框

时间:2019-02-27 12:59:11      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:position   text   网上   下载文件   views   tom   智能   mic   link   

怎样点击直接下载
直接让客户端浏览器下载已知类型的文件
实现点击链接直接下载文件
点击后直接下载而不是将其打开
写下载链接的时候,对于txt,doc,xls等文本类型的文件,点击链接时怎样才能直接下载,而不打开呢
如何左键点击连接连接直接下载.txt文件

网上搜到提供的方法都是用fso stream读取文件,然后通过修改http headers的办法,比较麻烦,而且效率很低。

IIS里边有一项Custom HTTP Headers 的选项,可以直接在里边修改Content-dispositionattachment即可。



Microsoft provides a way to override this "stream now" behavior at the server side using a custom HTTP Header in IIS. To add the custom header, launch Internet Information Services Manager and expand your Web sites to reveal the folder where multimedia content is stored. Right-click this folder and choose Properties. Click the HTTP Headers tab, followed by the Add button.

技术图片

For the Custom header name type: Content-disposition
For the Custom header value type: attachment

技术图片

Click OK, click Apply, click OK.

Visit one of the Web pages linking to your content download and test the links. You should be presented with the Save As dialog.

There is a catch to this solution. By setting the Content-disposition for the entire folder, your server will pop the Save As dialog box for any file called by a Web browser, including Web pages. There are two ways to solve this problem: only store media files in the folder where you modify the Content-disposition or set the attribute on-the-fly using code.

原文来自:http://www.jakeludington.com/windows_media_server_admin/20041209_using_custom_http_headers_to_prompt_for_video_file_downloads.html

 

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net

点击链接不在浏览器打开而是弹出下载对话框

标签:position   text   网上   下载文件   views   tom   智能   mic   link   

原文地址:https://www.cnblogs.com/sjwudhwhhw/p/10442942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!