首先我保留了
<a href="url"> File to download</a>
与我们在浏览器中一样的下载文件链接,但它在移动 Android 应用程序中不起作用。我再次保留了我使用的 JavaScript 点击函数
window.location(URL)
它在桌面浏览器中工作正常,但同样的方式在移动 WebView 应用程序中不起作用。
有人可以建议一种在 Android 移动 WebView 应用程序中下载文件的方法吗?
最佳答案
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
你可以尝试这个,即使在移动设备上它也适用于我。
关于javascript - Onclick 上的 href 链接文件未在 Android 移动网络应用程序中下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47365948/