Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    311
    Thanks
    17
    Thanked 0 Times in 0 Posts

    if(Cannot find server or DNS Error){

    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');
    }
    Last edited by fuzzy1; 07-13-2007 at 12:32 PM.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    You could possibly search for something specific in the url

    Take a look at this example, see if it helps

    http://www.huntingground.freeserve.c...ne_offline.htm
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Apr 2006
    Posts
    311
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Mr J View Post
    You could possibly search for something specific in the url

    Take a look at this example, see if it helps

    http://www.huntingground.freeserve.c...ne_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
    Code:
    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
    Code:
    <img src="site-url/image.gif"  onError="alert('Image missing or no internet connection')">
    I'll post result.

  • #5
    Regular Coder
    Join Date
    Apr 2006
    Posts
    311
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Might could clean this up a bit, but works as follows:
    PHP Code:
    <script>
    function 
    verify_connection(){
        var 
    connected document.getElementById('connected');
        var 
    thisIframe document.getElementById('check_statusIframe');
            if(
    connected.value!='false'){
                
    thisIframesrc="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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •