如何检测对HTML5“下载”的支持属性? [英] How to detect support for the HTML5 "download" attribute?

查看:113
本文介绍了如何检测对HTML5“下载”的支持属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML5中实现的新功能之一是定位标记的下载属性。此属性的好处是它为用户提供了下载在客户端应用程序中创建的内容的方法,例如图像(例如,从画布转换)。

One of the new features implemented in HTML5 is the download attribute for anchor tags. The benefit of this attribute is that it gives users the means to download content created within a client application, such as an image (converted from a canvas, for instance).

目前,对此功能的支持非常差,所以我想知道如何在浏览器中检测对此功能的支持。

Currently, support for this feature is very poor, so I'd like to know how can I detect support for this feature in a browser.

推荐答案

使用 Modernizr 方法:创建元素,并检查属性是否已定义:

Use the Modernizr approach: create the element, and check if the attribute is defined:

var a = document.createElement('a');
if (typeof a.download != "undefined") {
    alert('has support');
}

这篇关于如何检测对HTML5“下载”的支持属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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