Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ping server with javascript

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is it possible to ping a server with javascript? I know it is possible with server-side scripting, but that is not an option in this case. I would like to check if the server is "active" before redirecting the user to a webpage on the server.

thanx
-David
 
it is considerate of you to put effort for this kind of user friendliness. However there is no client side js that can do this for you. However if the server you are linking to is one you have access to you could use a little ingenuity and give visual cues on wether or not the site is active.

Try putting a green image (1px by 1px) on the server you are linking to. name this image the name you want. Do a setTimeout to check if the image is complete after three seconds or so. if the image is not complete set the image src to red.

here is a quick code example that I never tested :

<img src=&quot; name=another height=10 width=10>

<script>
function checkServerStatus()
{
if (!document.another.complete) // if it is not available
{
document.another.src = &quot;red.png&quot; // resides on your server
}
}
setTimeout(&quot;checkServerStatus()&quot;, 3000)
</script>

I didn't test this but I believe you could use similar tests with hidden image or image objects having for src an HTML page. This could make it even more interesting :)

Hope it helps. Gary &quot; Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top