0
  1. First I kept <a href="url"> File to download</a>link to download file as we do in browser but it's not working in mobile android app.

  2. Again I kept JavaScript on-click function in which I used window.location(URL) where it's working fine in desktop browser but the same way is not working in mobile web view app.

Can anyone suggest a way to download file in android mobile web view app?

Indrit Kello
  • 1,293
  • 8
  • 19
Money
  • 11
  • 3

2 Answers2

1
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);
}

You may try this, it is working for me even in mobile.

Indrit Kello
  • 1,293
  • 8
  • 19
  • 1
    I am using mobile app which is native app where every function will be running from backend server so the function which you gave also not working and not downloading file in mobile. – Money Nov 18 '17 at 13:17
  • If so you should add android tag in the question you made. Look at this answer, hope it helps you.. https://stackoverflow.com/questions/15758856/android-how-to-download-file-from-webserver – Indrit Kello Nov 18 '17 at 13:36
0

Sometimes (older devices - web browsers) this bug is real , I don't know what is the problem but try this :

   location.assign("https://www.w3schools.com");

Use assign not url or href . I hope so.

Nikola Lukic
  • 4,001
  • 6
  • 44
  • 75