How to detect support for the HTML5 "download" attribute?
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');
}
A single-line if
condition to keep things simplified:
if (document.createElement('a').download==undefined && e.target.hasAttribute('download'))
{
e.preventDefault();
console.log('Error: this is a download link, please right-click to save the file.');
}
Support for the download
attribute is spotty (Chrome 14+, Firefox 20+, IE13+, Safari 10+ and no support in (real) Opera. The script above will not interfere with supported browsers.