Jimmy
Jimmy

Reputation: 473

Javascript : Check local file's existence using javascript

var req = new XMLHttpRequest();  
req.open('GET', '20121209.xml', false);   
req.send(null);  
if(req.status == 0)
{ 
//file exist
}

I want to check whether file is existed or not in local machine using javascript. So I wrote the code like above. I can check when file is existed, but I cannot check when the file is not existed.

Finally I want to do something when file is not existed. Can I do this???

Upvotes: 0

Views: 394

Answers (1)

shannonman
shannonman

Reputation: 861

Javascript is sandboxed in the browser that is executing it, it can not access the client's local file system if the JS is served from a non-local location. Doing what you listed will make a request to

http://website.js.is.on.com/20121209.xml

Upvotes: 4

Related Questions