Quantcast
Channel: Adobe Community : All Content - Edge Animate
Viewing all articles
Browse latest Browse all 9897

Check if local URL exists

$
0
0

Hi,

 

I would to perform a validation on whether a local file/URL exists.

 

I have searched into this trying various examples however none of them seem to work including the following:

 

function doesFileExist(urlToFile)
{    var xhr = new XMLHttpRequest();    xhr.open('HEAD', urlToFile, false);    xhr.send();       if (xhr.status == "404") {        return false;    } else {        return true;    }
}




var result = doesFileExist("page2.html");

if (result == true) {
    console.log("yes");
} else    console.log("no");
}  

 

In this example if my file does exists I get the correct output of "yes". However if this file does not exist I get the following error:

 

XMLHttpRequest cannot load file:///D:/edgeTest/page2.html. Cross origin requests are only supported for HTTP.

 

Can anyone give me any information to why this might be happening?

 

Thanks


Viewing all articles
Browse latest Browse all 9897

Trending Articles