3

Is there anyway with javascript/jQuery to check if a website is up?

You're limited by the single origin policy I don't think you can use a standard Ajax request, but is it possible to try and load a file (similar to wget) and get the status code of the reply another way?

This would be for a user side website checker, where they can check if multiple domains are "up" without having to use any code on a server.

e.g. I open a web page at checkmysite.org it sends an HTTP request to mysite.org to check whether it receives a response, and if so the domain is online

Pez Cuckow
  • 14,048
  • 16
  • 80
  • 130
  • Possibly what you are searching for is implemented with ajax and get request. eg. http://stackoverflow.com/questions/6700822/jquery-how-to-get-the-http-status-code-from-within-the-ajax-error-method – Jimmy Kane Dec 28 '12 at 11:14
  • 3
    @JimmyKane unfortunately I don't think that will work cross domain – Pez Cuckow Dec 28 '12 at 11:15

1 Answers1

0

The single origin policy exists for a very good reason. What you're asking is effectively the same as "how can I defeat the single origin policy?".

You could always work around the policy with the co-operation of the server-end, for some specific known server. (e.g: CORS, cross-domain.xml in flash, <script> tag, etc).

Why is it so important that this not have help from the server at checkmysite.org? It could host an absolutely trivial php script which does the HEAD request for you. Your JavaScript code could just do a normal GET request to the PHP script.

David-SkyMesh
  • 5,041
  • 1
  • 31
  • 38