I need to check if an external URL redirects and if it does, get the new URL.
I tried doing this:
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (this.status < 400 && this.status >= 300) {
alert('this redirects to ' + this.getResponseHeader("Location"));
} else {
alert('doesn\'t redirect ');
}
};
xhr.open('HEAD', 'http://example.com/test', true);
xhr.send();
from this post: detecting a redirect with javascript - how?
but it gets blocked by CORS policy. Is there any way around that?