| 1:12 pm on Apr 14, 2005 (gmt 0)|
I asked this a while back and got zero response and came to the conclusion that with JS alone there is no way. However, you can use PHP to determine if the site is available and do a document.write based on your findings. Similarly (though slightly more complex) you can do it via a perl SSI script.
Hope that helps a bit :)
| 1:39 pm on Apr 14, 2005 (gmt 0)|
This is possible using an XMLHTTPRequest. These are now supported in the majority of browsers.
Better off with someone else's code:
- in particular, the heading: Does a URL exist?
Oh yes. Undert 'normal' security settings, this can only be used to load¦test a document within the same domain. If you need to test for a page outside you own domain, then you will need some kind of server-side solution (possibly using server-side XMLHTTPRequest).
| 3:45 pm on Apr 14, 2005 (gmt 0)|
There's always the ol' "load it in a hidden iframe and poll onerror" technique (in which you are left wondering if the user's browser actually supports onerror on iframes).
| 4:23 pm on Apr 14, 2005 (gmt 0)|
I pull a .gif file from the target site and use 'onerror' there.
| 4:49 pm on Apr 14, 2005 (gmt 0)|
Internet routing issues make what you're asking for problematic at best. Just because you can connect from your IP address doesn't mean the visitor can connect, vice versa if you can't connect it doesn't mean the site isn't up and running and available to your visitor.
| 5:16 pm on Apr 14, 2005 (gmt 0)|
"load it in a hidden iframe and poll onerror"
That sounds quite good. The requirements ask merely for testing a website, so we have no risk of a custom 404 page.
Not so confident about browsers being nice, and actually firing that onerror.
Browsers? Never trust 'em me.
"pull a .gif file from the target site and use 'onerror'"
I was thinking of suggesting something like that. It's cool, just as long as:
a) The website isn't arbitrary (eg: typed in by user).
b) The website doesn't decide to remove the image.
Jalarie, I have always had a problem geting Mozilla to fire an onerror. Does it work for you?
I would like to interrupt this thread to express my surprise that the ability to access response headers via script isn't a standard browser API feature.
(..or am I missing something?)
| 5:51 pm on Apr 14, 2005 (gmt 0)|
|Bernard Marx: Jalarie, I have always had a problem geting Mozilla to fire an onerror. Does it work for you? |
Yes. I just retested it for the "onerror" which I mentioned above.
| 6:15 pm on Apr 14, 2005 (gmt 0)|
Hmm. Not working for me still (Firefox).
Perhaps it just doesn't work offline. I'll give it a pop online later.