0

I want to validate the existence of a HTML file before opening it in a new tab.

How can I do so using pure JavaScript?

I am storing the file's location in path variable.

path = "F:\Folder_JS\File1.html";
//I want to check here whether there exists such a file or not before opening it new tab
myWindow = window.open(path,'_blank');
jwpfox
  • 5,124
  • 11
  • 45
  • 42
Karan Parikh
  • 311
  • 3
  • 18
  • 1
    Looks like a duplicate of [Check if a file exists locally using javascript ONLY](http://stackoverflow.com/questions/5115141/check-if-a-file-exists-locally-using-javascript-only) – Ivan Oct 16 '16 at 08:44

1 Answers1

0

You may try it by js:

var url = 'File1.html'; //use file url not real path. ex: folder/File1.html
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
if(http.status!=404){
    //file exist
}else{
    //file not exist
}
AHJeebon
  • 1,218
  • 1
  • 12
  • 17