Jump to content

Needing URL Testing


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 post
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 post
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? Edited by trinaryatom
Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...