Check if a file exists locally using JavaScript only

后端 未结 10 1706
盖世英雄少女心
盖世英雄少女心 2020-12-03 14:01

I want to check if a file exists locally, where the HTML file is located. It has to be JavaScript. JavaScript will never be disabled. jQuery is not good but can do.

10条回答
  •  佛祖请我去吃肉
    2020-12-03 14:42

    Try this:

    window.onclick=(function(){
      try {
        var file = window.open("file://mnt/sdcard/download/Click.ogg");
        setTimeout('file.close()', 100);
        setTimeout("alert('Audio file found. Have a nice day!');", 101);
      } catch(err) {
        var wantstodl=confirm("Warning:\n the file, Click.ogg is not found.\n do you want to download it?\n "+err.message);
        if (wantstodl) {
          window.open("https://www.dropbox.com/s/qs9v6g2vru32xoe/Click.ogg?dl=1"); //downloads the audio file
        }
      }
    });
    

提交回复
热议问题