Jump to content

Needing URL Testing


trinaryatom

Recommended Posts

Looking for some JavaScript that can tell if a file or website is available.For example:

if (URL exists)  {	document.write(<div> + "Content Box" + </div>)  }else  {	document.write(<div> + "Unavailable" + </div>)  }

A real time example would be something like say an embed code from a website and having an alternate setup for when the website was down.

Link to comment
Share on other sites

If you need to use Javascript, about the only thing you can do is send an ajax request and check the response status. There might be a delay there, the delay might be up to 30 seconds if the server exists but times out. The major downside to that is that the entire file will end up being downloaded, and that will only work for files on your own server. If you need to test remote files then Javascript alone is not an option.

Link to comment
Share on other sites

If you need to use Javascript, about the only thing you can do is send an ajax request and check the response status. There might be a delay there, the delay might be up to 30 seconds if the server exists but times out. The major downside to that is that the entire file will end up being downloaded, and that will only work for files on your own server. If you need to test remote files then Javascript alone is not an option.
Ah, well... dang.So if i may ask, what is the proper code to do a something like this. PHP?
Link to comment
Share on other sites

With PHP you can at least send a request for only the headers to see if the content exists without downloading the whole thing. There's still a delay during the connection though. You can always have Javascript send an ajax request to a PHP script on your server which does the check and returns the result back to Javascript.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...