Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 12:16 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: HTML5: detecting if internet connection is available
PostPosted: April 1st, 2019, 12:27 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Trying to put 2 textboxes on the first (sign-in) page of an HTML5 lesson that will show whether an internet connection is available or not.

Found JS that will create an alert (see below), but not sure how to adapt this to show/hide 2 textboxes, one saying internet connection available, another second box saying no internet connection is available.

Can create 2 textboxes (for example, T1 and T2), but not sure how to identify them in the JS (see below) and then hide or show them (toggle between?) based on whether the connection is detected or not.

Any help appreciated.

Code:
<script>
    function status()
    {
        if(navigator.onLine)
        {
            alert("Browser is online");
        }
        else
        {
            alert("Browser is offline");
        }
    }
</script>


Thank you for your help.

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: HTML5: detecting if internet connection is available
PostPosted: April 1st, 2019, 1:14 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Opus doesn't understand JavaScript in the editor: Put window in front of it.

Code:
if (window.navigator.onLine){

myStatus = "You are online";
} else {
myStatus = "You are offline"
}


</mack>

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject: Re: HTML5: detecting if internet connection is available
PostPosted: April 1st, 2019, 2:02 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Thanks, Mack.

That works nicely!

_________________
Stephen


For this message Stephen has been thanked by : mackavi


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group