强制链接的MP3文件下载/另存为 [英] Force link to mp3 file to download/save-as

查看:438
本文介绍了强制链接的MP3文件下载/另存为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站链接到MP3文件。(正常< A HREF =file.mp3> 标记)

I have links to mp3 files on my website (normal <a href="file.mp3"> tags).

但对于很多用户谁拥有的苹果的Quicktime 的安装,它会打开MP3文件,而不是当你点击链接拯救出来。

But for many users who have Apple Quicktime installed, it will open the mp3 files rather than "save" them when you click on the links.

您可以强制浏览器保存链接,而不是使用浏览器偏好?

Can you force the browser to save the link rather than using the browser preference?

我可以使用JavaScript或C#.NET和我我想找一个简单的解决方案,如果可能的。

I can use JavaScript or C# .NET and I'm looking for a simple solution if possible.

推荐答案

您需要设置与内容处置HTTP头设置为附件。这将强制浏览器弹出一个保存对话框。 873207 有一个干净的方式在C#中这样做。

You need to set a http header with "Content-Disposition" set to "attachment". This will force the browser to pop a save dialog. 873207 has a clean way of doing this in C#.

BUT ,喜欢的大同说,你可能不应该被默认做到这一点。这样做的一个很好的方式是提供一个正常的链接文件(你这样做的方式),并且提供旁边,迫使保存对话框二级链接。这样,你让少优的用户做一个简单的点击保存操作,以及让每一个其它用户做任何他们想要的MP3。

BUT, like Pax says, you probably shouldn't do this by default. A nice way of doing it is to provide a normal link to the file (the way you're doing it), and provide a secondary link beside it that forces the save dialog. That way you let the "less gifted" users do a simple click-to-save operation, as well as let every other user do whatever it is they want with the mp3.

这篇关于强制链接的MP3文件下载/另存为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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