Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Offline App JavaScript Internet status checking

Dear Programmers,

I have customized the below code from web to check internet connection availability. The script will return '1' when the internet connection available and return '2' when the internet connection not available.

It works perfect when I take the survey using browser in Mobile, Tablets and PCs.

However, it is not working (i.e, always returns '2') when taking survey using offline app, though the Mobile or Tablet connected to the internet.

I look for your ideas or some inputs on why it cannot function on offline app.


    <script type="text/javascript" language="javascript">

        var internet_status = "";

        function doesConnectionExist() 
   {
            var xhr = new XMLHttpRequest();
            var file = "https://testing.com/gmaps/graphics/test.png";
            var randomNum = Math.round(Math.random() * 10000);

            xhr.open('HEAD', file + "?rand=" + randomNum, true);
            xhr.send();

            xhr.addEventListener("readystatechange", processRequest, false);

            function processRequest(e) 
  {
                if (xhr.readyState == 4) 
{
                    if (xhr.status >= 200 && xhr.status < 304) 
{
                      document.mainform.internet_status.value = "1";  // Internet connection exist.
                      } 
    else 
{
                      document.mainform.internet_status.value = "2";  // Internet connection does not exist.
                        
                      }
                }
             }

         }
    </script>


Thanks,
Lawrence

P.S: I have sent an email to Support in case if they have any solution.
asked Jan 26, 2017 by Lawrence Bronze (2,100 points)
retagged Jan 26, 2017 by Walter Williams

1 Answer

0 votes
answered Mar 22, 2018 by skptricks
...