I'm attempting to verify the existence of a URL from another domain on my own domain ('https://radiusofficefurniture.ie') using JavaScript like this:
var request = new XMLHttpRequest();
request.open('GET', 'https://www.mozilla.org', true);
request.onreadystatechange = function(){
if (request.readyState === 4){
if (request.status === 404) {
alert("Oh no, it doesn't exist!");
}
}
};
request.send();
However, I encountered a CORS policy issue. The error message reads:
Access to XMLHttpRequest at 'https://www.mozilla.org/' from origin 'https://radiusofficefurniture.ie' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Can someone please assist me in figuring out how to determine the existence of URLs from other domains using JavaScript? I need to add an HTML tag to my site if the URL from another domain exists.