Is there a way to determine whether a browser supports using data URIs for hyperlinks, besides browser sniffing?
Here's the context:
I'm creating a link that either downloads a CSV file of information generated via JavaScript using a handy data URI or, if the browser does not support the use of data URIs for hyperlinks, generates an HTML table of the desired content.
Right now my code checks the existence of the window.URL
property, which doesn't exist in IE9 and below. (This is working okay for now, because the IE users I need to support are running in compatibility mode, which emulates IE8.)
if(window.URL){
downloadLink.href = "data:text/csv;charset=utf-8," + encodeURIComponent(data);
downloadLink.setAttribute("download","download.csv");
}else{
downloadLink.href= "#";
downloadLink.innerHTML = "table view";
downloadLink.onclick = function(){
// build and display HTML table
return false;
};
}
However, there's some overlap with newer versions of Internet Explorer (10, 11, as well as Edge) in that they support the window.URL object but do not allow data URIs for hyperlinks.
How do I ensure that the link to download a CSV is never displayed to a browser that does not support such fanciness?