Online or Offline

Status:

By checking the documents current location a script can determine if you are on or offline because the documents location will be different when online.

The online location for this page is
http//www.huntingground.freeserve.co.uk/scripts/online_offline.htm

but where it resides on my harddrive the location for this page is
file:///C:/Documents and Settings/My Documents/Website/huntingground/scripts/online_offline.htm

The first thing to do is get the current location of this page

url=unescape(document.location)

Then check for something that is in the online address but not in the local address and knowing that my web address is www.huntingground.co.uk that is what I checked for using

if(url.indexOf("www.huntingground.freeserve.co.uk")!= -1){

If this string is not found in the address then the script knows that I am not online and can be directed to do something locally or visa versa.

<script type="text/javascript">
<!--

function chkUrl(){
url=unescape(document.location)

if(url.indexOf("YourWebStringToSearchFor")!= -1){ // if this string is found
alert("You are online") // do this if online
}
else{
alert("You are Offline") // do this if offline
}

}

// add onload="chkUrl()" to the opening BODY tag

//-->
</script>