Why doesn’t the download attribute work in Lollipop’s web view?

In my javascript-enabled, Android Lollipop web view, I try to let the user download a simple file hello.txt by using <a>‘s download attribute:

// Store some text in a data URL.
var dataUrl = (window.URL || window.webkitURL).createObjectURL(
    new Blob(["Hello world. :)"]));

// Create a link that lets the user download the text file as hello.txt.
var downloadLink = document.createElement('a');
downloadLink.setAttribute('href', dataUrl);
downloadLink.setAttribute('download', 'hello.txt');
downloadLink.innerHTML = 'Click to download hello.txt.';

// Display the link.
document.getElementById('container').appendChild(downloadLink);

This works for Desktop – try clicking the link in this Fiddle.

However, clicking the link within the web view does nothing. Why? Do I need to somehow enable downloads for Android web views?


Source: html5

Leave a Reply