View Full Version : Check to see if site is down...
Jasonb61
08-28-2002, 12:46 AM
Is there a way to check if a site is down or not in Javascript? Like right now my site sever is down (http://mainframe.vze.com) and I had to edit the shorturl to go to a differant site... but I want it to take the person to a differant page if the site is down.
Please help me!
Thanks,
JohnnyX
joh6nn
08-28-2002, 04:53 AM
do you mean, if someone comes to your site, and your site is down, send them to another site, or what do you mean, exactly?
jalarie
08-28-2002, 02:44 PM
Place an image on your server, then add the following code to your page:
<script type="text/javascript">
<!-- Hide this code from non-JavaScript browsers
function NoServer() {
alert('The server is down.');
}
// End hiding -->
</script>
<IMG src="http://your_address.com/target.gif"
width="1" height="1" onerror="NoServer();"/>
:thumbsup:
Jasonb61
08-28-2002, 09:46 PM
Is there a way to tell if the picture accualy loaded OK?
joh6nn
08-29-2002, 01:02 AM
that's what jalarie's code does. pictures come with an onError event handler. if there's a problem loading the picture ( eg, the server is down, and the file can't be found), then this event fires, and the event handler executes. jalarie's code pops up an alert, telling you that the server is down. what i recommend, because it's less intrusive, is that you have the code set a new url for the picture. what this does, is let you have a "Server is Up :-)" picture, and a "Server is Down :-(" picture. the server is up picture rests on the server you test for, and the server is down picture rests on the same server as the website. code looks like this:
<script type="text/javascript">
<!-- Hide this code from non-JavaScript browsers
function NoServer(img) {
img.src = "http://thisserver.com/serverdown.gif";
}
// End hiding -->
</script>
<IMG src="http://thatserver.com/serverup.gif"
width="100" height="100" onerror="NoServer(this);"/>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.