How can I control url is exist or not?

Hello,

I have a lot of site names at our disposal. Some of these sites do not. Can we check with JS if they exist? like returning true if it exists…
I found a code below but
XMLHttpRequest requires API. Do you have an example or solution that you use for this issue?


function ifUrlExist(url, callback) {
var request = new XMLHttpRequest;
request.open(‘GET’, url, true);
request.setRequestHeader(‘Content-Type’, ‘application/x-www-form-urlencoded; charset=UTF-8’);
request.setRequestHeader(‘Accept’, ‘/’);
request.onprogress = function(event) {
var status = event.target.status;
var statusFirstNumber = (status).toString()[0];
switch (statusFirstNumber) {
case ‘2’:
request.abort();
return callback(true);
default:
request.abort();
return callback(false);
};
};
request.send(‘’);
};
ifUrlExist(url,function(exists)
{
console.log(exists);
});


Hello,

To better understanding, could you please show resource which you get data? I am not clear on resource.