-1

I am making an app with web view inside of it which handles offline html pages. One html page contains contact and Rating review. I would like to show the Rating review inside an iframe from where user can review the items but when internet is not availaible instead of showing no connection availaible. I would like to hide the iframe or instead show an image or default html page.

Is this possible. I tried the below link but it doesn't work for me. if there is no internet connection, hide iframe

Thanks in advance.

Azeez Kallayi
  • 2,567
  • 1
  • 15
  • 19
mark22
  • 17
  • 7
  • 1
    Here is an article to help you out: https://davidwalsh.name/detecting-online – Milan Chheda Jan 25 '18 at 06:45
  • @MilanChheda would it very easy if any example or how to implement the solution would be posted. Everything I learned, all credit goest to stack overflow...so when new things comes...I get stuck and this is completely new to me. – mark22 Jan 25 '18 at 06:53

2 Answers2

1

Using ajax,

$.ajax({
    url: "<any url you prefer>",
    timeout: 10000,
    error: function(jqXHR) { 
        if(jqXHR.status==0) {
            alert(" No connection");
        }
    },
    success: function() {
        alert("Connectivity");
    }
});

Or you can try downloading some file into your server to check connectivity, without using ajax.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
 if (! window.jQuery) {
 alert('No Connection !!');
  }
 else {
 // internet connection established
 }
</script>
Vishwa
  • 801
  • 11
  • 26
0

Here is an extremely simple example to help you out. Save this as HTML and open in your browser with internet connection ON and with internet connect OFF:

<html>

<head>
  <script>
    alert(navigator.onLine)
  </script>
</head>

</html>

If navigator.onLine gives you true, means internet is working fine.

Milan Chheda
  • 8,159
  • 3
  • 20
  • 35