0

I want to reload the current page with javascript if a specific url is doing a redirection.I don't need to know the redirection url.The xhr request is being performed and i do get 302 redirect when i inspect the request but my specific redirection isn't happening.

var xhr = new XMLHttpRequest();
xhr.open('HEAD', 'https://www.filterbypass.me/s.php?k=BbrSU%2F%2F39m5gKhLDr31ZqjKYgrAdALscySz%2B6YarDYTH5G9hSDc%2B&b=4&f=norefer');
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4) {
        if (xhr.status == 301 || xhr.status == 302) {
            //url expired , reload
            console.log('perform redirection');
            window.location.replace('https://www.google.com');
        }
    }
};
xhr.send();

I don't see the console.log and i already tried with xhr.readyState == 2.

user2650277
  • 6,289
  • 17
  • 63
  • 132
  • 2
    Try putting `console.log(xhr.readyState, xhr.status)` at the beginning of the callback function. – Barmar Mar 07 '19 at 18:50
  • Then the next question is: does filterbypass.me have CORS support? Usually, cross-domain XHR is blocked, unless the server you're connecting to explicitly allows it. – IceMetalPunk Mar 07 '19 at 18:51
  • @IceMetalPunk It has CORS headers and if there was an issue with cors redirect i would see it in chrome dev console – user2650277 Mar 07 '19 at 18:54
  • @Barmar i am getting response 200 but google dev console show 302 status code – user2650277 Mar 09 '19 at 16:28
  • Try using `readyState == 2`. That's when the response headers have been received. – Barmar Mar 09 '19 at 18:42
  • Just realized this is answered here: https://stackoverflow.com/questions/3820663/is-it-possible-for-xhr-head-requests-to-not-follow-redirects-301-302 XHR transparently follows redirects, so you don't get the callbacks firing until it hits the final destination. And it's apparently not (yet) possible to handle that manually, though it sounds like it's being considered for future specs. – IceMetalPunk Mar 11 '19 at 19:39

0 Answers0