Check url availability using javascript

Is it possible through jQuery (or plain javascript) to check if a webpage is accessible in another domain? I tried to get response headers using an ajax call, but I get an error message no matter which site outside of my own domain I am testing.

Do I really need a proxy script on my server or can I skip this request?

+3
source share
3 answers

Yes, you need to use a proxy script on your server. JavaScript cannot be used in a browser to request resources by domain, according to a policy of the same origin .

0
source

Is it possible through jQuery (or plain javascript) to check if a webpage is accessible in another domain?

Due to the same default restriction for the source, you need a proxy bridge on your server, unless the remote server implements JSONP , which, obviously, we cannot accept for the general case.

+2
source

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

If the onerror event fires, the image and possibly the entire site do not work.

If it fires after 5 seconds or so, it probably expired, so the whole site is likely to be unavailable.

+2
source

Source: https://habr.com/ru/post/1239828/


All Articles