homepage Welcome to WebmasterWorld Guest from 23.22.128.96
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Check if a website is available?
How can I do this?
Gary_King




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

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!

 

SimmoAka




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

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!

Bernard Marx




msg:1476262
 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:

[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>

Rambo Tribble




msg:1476263
 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).

jalarie




msg:1476264
 4:23 pm on Apr 14, 2005 (gmt 0)

I pull a .gif file from the target site and use 'onerror' there.

incrediBILL




msg:1476265
 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.

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

Bernard Marx




msg:1476266
 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?)

jalarie




msg:1476267
 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.

Bernard Marx




msg:1476268
 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved