Checking if web server is online/offline [duplicate]

左心房为你撑大大i 提交于 2019-12-25 08:48:28

问题


How would I check if a web server is online/offline from my domain? I've already tried an $ajax call with jsonp, but if the server isn't responding with json, then that doesn't work. Is there any other way to get an http response from a server?


回答1:


Just copied shamelessly from one website for easiness:

<img src="http://site-to-check.com/online.png" alt="status" onerror="this.src='files/offline.png'" />

The setup is:

An online icon (online.png) on the remote server you want to see the status of. An offline icon (offline.png) on the server that is going to show the status page.

If the image on the remote server fails to load, the onerror event is triggered and the javascript rewrites the image tag to show the offline image. You can use relative or absolute paths for the offline image. This snippet is fully compatible with all major browsers, including Internet Explorer down to version 5.5!




回答2:


As i understand, you want to know, if the website is online\offline How about this solution?



来源:https://stackoverflow.com/questions/23997675/checking-if-web-server-is-online-offline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!