How to detect HTTP status from JavaScript

后端 未结 4 1744
没有蜡笔的小新
没有蜡笔的小新 2020-12-25 14:59

I want to detect in a script, which could be deployed beyond my control, whether the page was delivered with a HTTP status of 200, 404 or 500 etc.

This can\'t be don

4条回答
  •  执笔经年
    2020-12-25 15:34

    Have the page make a XMLHttpRequest to itself (using location.href or document.URL) and check the HTTP status you get. Seems to be pretty portable way to me. Why you would do a thing like this is beyond my understanding though ;)

提交回复
热议问题