Skip to content Skip to sidebar Skip to footer

Test Url Availability With Javascript

Is it possible through jQuery (or plain javascript) to test if a webpage on another domain is available? I tried getting the response headers with an ajax-call but I get an error n

Solution 1:

Is it possible through jQuery (or plain javascript) to test if a webpage on another domain is available?

Due to same origin policy restriction you need a proxy/bridge on your server unless the remote server implements JSONP which obviously we cannot assume for the general case.

Solution 2:

You can create an <img> tag that points to an existing image on the external domain.

If the onerror event fires, image, and perhaps the entire site, is down.

If it fires after 5 seconds or so, it probably timed out, so the entire site is likely to be down.

Solution 3:

Yes, you need to use a proxy script on your server. JavaScript cannot be used in a browser to request resources across domains, as per the same-origin policy.

Post a Comment for "Test Url Availability With Javascript"