Click to See Complete Forum and Search --> : Script does not work?!


man
09-14-2003, 09:42 AM
Hi folks, this script checkīs up if my Server is on, but if the Server is on or off, every time i was linked to the Go.htm.
Why? Is there s.th. wrong in this Script?

<script language="JavaScript">
Bild = new Image(); Bild.src = "http://hackstube.homeip.net/mmc.gif";
var loop = 4, hoch = 24;
function Servertest()
{
if(Bild.height == hoch)
window.location.href="http://www.hackstube.de/Go.htm";
else if (loop>0)
{loop--; window.setTimeout("Servertest()",1000);}
else
window.location.href="http://www.hackstube.de/Stop.htm";
}
Servertest();
</script>

At this time my Server is realy off! So you can test the script...

pyro
09-14-2003, 09:51 AM
You might like something like this better:

<script type="text/javascript">

var img = new Image();
img.src = 'http://www.yourdomain.com/images/someimg.png';
img.onload = function () {document.getElementById("online").style.backgroundColor="#00ff00";}
img.onerror = function () {document.getElementById("online").style.backgroundColor="#ff0000";}

</script>

Server Status: <span id="online" style="width: 10px; height: 10px; background-color: transparent; font-size: 1px;"></span>

man
09-14-2003, 11:06 AM
thx for your Version, looks good and after a test it realy works fine when Server is off, but it takes about 20 seconds to display the red color. Thatīs to long...

Do you have an other idea?

If it would be possible with the redirection Links like the example in the first post.

man
09-14-2003, 11:17 AM
I also tried this script but it takes about 20 second to check server status, too!

<script TYPE="text/javascript">
var on_line = "No";
</script>
<script type="text/JavaScript" src="http://my_domain.com/on-line.js"></script>
<script TYPE="text/javascript">
if (on_line != "Yes")
document.write("Server is offline<br>");
else
document.write("Server is online<br>");
</script>

Khalid Ali
09-14-2003, 11:23 AM
If what pyro suggested is taking 20 secs then thats how long your image takes to preload?..use a smaller image...

man
09-14-2003, 11:33 AM
If the Server is off, what image will be loaded?

The problem is the off message. It takes 20 seconds to say "Tere is no Server"! To long i think.

man
09-14-2003, 12:35 PM
OK Folks it was my fault!!

I made the mistake to put the complet Code into the body ...

As i put the script part into the head it wondered how fast it was.... so it works perfect!

Thx for your support!

Originally posted by pyro
You might like something like this better:

<script type="text/javascript">

var img = new Image();
img.src = 'http://www.yourdomain.com/images/someimg.png';
img.onload = function () {document.getElementById("online").style.backgroundColor="#00ff00";}
img.onerror = function () {document.getElementById("online").style.backgroundColor="#ff0000";}

</script>

Server Status: <span id="online" style="width: 10px; height: 10px; background-color: transparent; font-size: 1px;"></span>

pyro
09-14-2003, 12:49 PM
You bet. Glad it's working for you... :)

man
09-14-2003, 01:17 PM
How must the script look like if i want to offer a Link for this part...

img.onload = function () {document.getElementById("online").style.backgroundColor="#00ff00";}

...so that the user can go to the Server!?

For example http://hackstube.homeip.net


Originally posted by pyro
You bet. Glad it's working for you... :)

pyro
09-14-2003, 01:44 PM
Try it like this:

<script type="text/javascript">

var img = new Image();
img.src = "http://www.yourdomain.com/images/someimg.png";
img.onload = function () {
document.getElementById("online").style.backgroundColor="#00ff00";
document.getElementById("onlinelink").innerHTML = "<a href=\"http://www.yourdomain.com\">http://www.yourdomain.com</a>";
}
img.onerror = function () {
document.getElementById("online").style.backgroundColor="#ff0000";
}

</script>

<p>Server Status: <span id="online" style="width: 10px; height: 10px; background-color: transparent; font-size: 1px;"></span><span id="onlinelink"></span></p>

man
09-14-2003, 02:06 PM
Originally posted by pyro
Try it like this:

<script type="text/javascript">

var img = new Image();
img.src = "http://www.yourdomain.com/images/someimg.png";
img.onload = function () {
document.getElementById("online").style.backgroundColor="#00ff00";
document.getElementById("onlinelink").innerHTML = "<a href=\"http://www.yourdomain.com\">http://www.yourdomain.com</a>";
}
img.onerror = function () {
document.getElementById("online").style.backgroundColor="#ff0000";
}

</script>

<p>Server Status: <span id="online" style="width: 10px; height: 10px; background-color: transparent; font-size: 1px;"></span><span id="onlinelink"></span></p>

[Sorry, but there is no Link displayed !]

Forget this!!!!! I made a mistake. It works Fine!!!!!!!!

pyro
09-14-2003, 02:16 PM
Worked fine for me, when I pointed the img.src line to an image on my server...

man
09-14-2003, 02:22 PM
Originally posted by pyro
Worked fine for me, when I pointed the img.src line to an image on my server...

Yes i know!!
I made a mistake with the Link ;)

Thx anyway....

Good work!!

pyro
09-14-2003, 02:27 PM
You are welcome... :)