0

How can I get response codes from site using JS? This is a site which I don't own. Is this possible?

For an example, I'm trying to make a script if that site loads, then show response in my website. I don't just want 200 or 404. I want every single status code shown for that site. Thanks.

Berglund
  • 636
  • 2
  • 7
  • 20
  • https://stackoverflow.com/questions/3922989/how-to-check-if-page-exists-using-javascript – baao Apr 20 '18 at 20:41
  • 1
    You've asked two different questions. _Getting response codes_ is one and determining _if that site loads_. These are different. Which do you want. – Randy Casburn Apr 20 '18 at 20:41
  • I don't just want 200 or 404. I want every single status code shown for that site. – Berglund Apr 20 '18 at 20:47
  • You understand that they are not specific to a site, right? HTTP Status Codes are a standard: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status – Alexander Nied Apr 20 '18 at 20:55
  • Yes, Alexander. For an example I tried making a JS script which shows the every status of a website for an example bbc.com, and then implemented it on a test page I own. So visitor comes to my site and he can check the status of bbc from my site, whether it's down or now. – Berglund Apr 20 '18 at 20:57
  • The issue I get is, not every response codes shown in my script. It logs in console but not in my script. And nothings wrong with my script. – Berglund Apr 20 '18 at 20:59

1 Answers1

0

As far as I know, this is not possible due to CORS. You can not get all HTTP response status codes from a website which you don't own. (unless CORS is enabled for all requesters)

Gihan
  • 3,144
  • 2
  • 9
  • 36
  • I want to check, every status code on that site. I tried to achieve this but the response code I get is 0 for some statuses on my end. The console shows fine. – Berglund Apr 20 '18 at 20:43
  • 1
    Randy Casburn, Can you please explain your opinion? – Gihan Apr 20 '18 at 20:45
  • So that means no solution? – Berglund Apr 20 '18 at 20:48
  • 1
    You can try using a free CORS Proxy. Or build your own one. But if your intention is to show your visitors what they get, then It won't work. – Gihan Apr 20 '18 at 20:50
  • yes what i want is check the status code of that site from my website's visitors end. – Berglund Apr 20 '18 at 20:52
  • Now that the OP has clarified `all status codes`, your answer is no wrong. The OP was unclear when saying _if that site loads_. Please make a simple edit so I can remove my downvote. – Randy Casburn Apr 20 '18 at 21:02
  • is this possible or not ? someone please tell me. – Berglund Apr 20 '18 at 21:09