...

View Full Version : if(Cannot find server or DNS Error){



fuzzy1
07-13-2007, 01:21 PM
Hey There,

Is there any way to manage something like
if(Cannot find server or DNS Error){
window.close();
}

or alternatively ...
if(there is NO internet connectivity){
window.close();
}

OR
if(there IS internet connectivity){
alert('hooray');
}

Mr J
07-13-2007, 02:57 PM
You could possibly search for something specific in the url

Take a look at this example, see if it helps

www.huntingground.freeserve.co.uk/scripts/online_offline.htm

ess
07-13-2007, 04:00 PM
How about the following.

You create an image object in JavaScript...and supply the domain name i.e. http://exampledomain.com as the source of the image....and you time the call to the image source.

If an error is generated.....the client is connected to the internet...if no error is generated...after a period of time has elapsed...one can deduce that there is not an active connection to the Internet for that client.

fuzzy1
07-13-2007, 05:43 PM
You could possibly search for something specific in the url

Take a look at this example, see if it helps

www.huntingground.freeserve.co.uk/scripts/online_offline.htm

Thanks Mr J, interesting little script there, but it appears to be more about determining the location of the current page ([served locally on c:/-- offline] or remotely at www.somedomain.com/ -- online).
What I need is a way to determine whether or not a connection can be established to somedomain.com is possible
if(connected){do this} else{do that}(if tablet pc has connection run local script, if not abort).

I'm looking into ess suggestion of using a call to an image, something like

<img src="site-url/image.gif" onError="alert('Image missing or no internet connection')"> I'll post result.

fuzzy1
07-13-2007, 07:24 PM
Might could clean this up a bit, but works as follows:

<script>
function verify_connection(){
var connected = document.getElementById('connected');
var thisIframe = document.getElementById('check_statusIframe');
if(connected.value!='false'){
thisIframe. src="http://mydomain.com/crm/checkStatus.php";
}
if(connected.value=='false'){
alert("no connection")
window.close();
}
}
</script>
<!-- verify host connection first - if connected run scripts - else close/abort -->
<body onload="verify_connection()">
<img src="http://mydomain.com/connected.gif" onError="document.getElementById('connected').value='false';">
<input type="hidden" id ="connected">
<!-- END verify connection -->
<iframe name="check_statusIframe" width="400" height="400" frameborder="1" application="yes" border="1">
</iframe>checkStatus.php by the way... checks the status of mysql_table provided a connection is available.:rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum