Welcome to WebmasterWorld Guest from 23.22.79.235

Forum Moderators: open

Message Too Old, No Replies

Check if a website is available?

How can I do this?

   
9:58 pm on Mar 28, 2005 (gmt 0)

10+ Year Member



How can I check if a website (like www.example.com ) is available/connectable and if it is, then automatically redirect to there? Otherwise if not, then don't do anything?

Thanks!

1:12 pm on Apr 14, 2005 (gmt 0)

10+ Year Member



Hi

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 :)

Simmo!

1:39 pm on Apr 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is possible using an XMLHTTPRequest. These are now supported in the majority of browsers.

Better off with someone else's code:

[jibbering.com...]

- in particular, the heading: Does a URL exist?

<edit>
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).
</edit>

3:45 pm on Apr 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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)

10+ Year Member



I pull a .gif file from the target site and use 'onerror' there.
4:49 pm on Apr 14, 2005 (gmt 0)

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.

What that said, the best solution would be something in the browser using javascript, not at the server level.

5:16 pm on Apr 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"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)

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



Hmm. Not working for me still (Firefox).
Perhaps it just doesn't work offline. I'll give it a pop online later.