将 MIME 类型添加到 HTML 链接 [英] Add mime type to HTML link

查看:34
本文介绍了将 MIME 类型添加到 HTML 链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何更改网络服务器中的 MIME 类型.我用它来确保浏览器下载我的 .scrpt 文件而不是打开纯文本版本.到目前为止一切顺利,但是否有可能对链接做同样的事情?我想链接到 GitHub 上的文件,但这将作为纯文本文件打开.我可以在链接中添加MIME 类型属性"以告诉浏览器下载文件吗?

I know how to change the MIME type in a webserver. I used this to make sure the browser downloads my .scrpt file instead of opening the plain text version. So far so good but is it possible to do the same with a link? I would like to link to a file on GitHub but this will open as a plain text file. Can I add a "MIME type attribute" to the link to tell the browser to download the file?

这是我想看到的:

<a mimetype="application/octet-stream" href="http://gist.github.com/raw/279094/39d5a2c1037288d5ee0ba1a17dca9edb368bbe42/RepairiPhotoDates.scpt">download</a>

推荐答案

是时候回答我自己的问题了.这是一个非常古老的问题,当时可能是不可能的,但从那时起发生了很多变化.HTML5 规范添加了 download 属性:

Time to answer my own question. This is a really old question and it probably wasn't possible at the time but lots has changed since then. The HTML5 spec added the download attribute:

<a href="hugepdf.pdf" download>Download file</a>

这将完全满足我的需求,告诉浏览器下载文件而不是打开它.感谢 Jonathan Svärdén 解决了我的岁月老问题!

This will do exactly what I need, tell the browser to download the file instead of opening it. Thanks to Jonathan Svärdén for solving my years old question!

这篇关于将 MIME 类型添加到 HTML 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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