0
Good night
I want to know if a particular file in a directory exists or not using pure JS, but none of the Answers on the internet worked.
answers I tried:
the answer 2 returns these errors:
would like to know how I can check whether or not one exists in a directory using only JS.
My code
function abrirPagina(){
var url = "umcaminhoqualquer/index.html";
if (validarPagina(url)){
window.location.href = (url); //redireciona para uma pagina local
}else{
alert('pagina ainda não existe');
}
}
function validarPagina(url){
//verificar e retornar true caso exista
}
thank you in advance
to check a "folder" on a site has no way... but for files, you can use ajax, and see if the returned code is 404 (not found), look: https://www.w3schools.com/js/js_ajax_intro.asp , in the case of this api, the code will be returned in status...but will only be the definitive when readyState for 4
– anon
ah, and it seems that the endemics you were trying were for the computer, summarizing it is impossible, a web page js access the computer file system..., what you can access are just other web pages, and depending on the configuration of the servers, only from the same site
– anon
if you want to access/manage PC files with JS recommend Node.js
– anon