0

I am looking for jquery/javascript code which checks system internet periodically and change the button.

Same like this http://html5-demos.appspot.com/static/navigator.onLine.html

I have code but it not work in all browser. I m looking for ajax kind thing

<script type="text/javascript">
        window.onload = function () {
            var tId = setInterval(function () {
                $("#link1, #link2).disabled = !navigator.onLine;
            }, 250);

        var status = navigator.onLine;
        if (status) {
            $("#link1").removeClass('diconnected').addClass('connected');
            $("#link2").removeClass('diconnected').addClass('connected');


        } else {
            $("#link1, #link2,").removeClass('connected').addClass('diconnected');
            $("#link1, #link2,").data('disabled', true);

        }
        }
    </script>

This answer How to detect online/offline event cross-browser? does not have any code for Ajax, i am looking for ajax

Community
  • 1
  • 1
Mike Phils
  • 3,475
  • 5
  • 24
  • 45
  • 1
    You make a start, and if you have any programming problems come back and ask for help (searching for possible solutions first), providing your attempted code and clearly stating where, and how, it failed to work. – David Thomas Nov 29 '14 at 18:53
  • Have you tried viewing source on that page? The `navigator.onLine` is right there in line 208 – imjared Nov 29 '14 at 18:53
  • @DavidThomas: code updated – Mike Phils Nov 29 '14 at 18:59
  • 1
    Which browser(s) does it fail in, and do they implement the `navigator.online` method? – David Thomas Nov 29 '14 at 19:02
  • Firefox and mobile browser.And each time i have refresh the page to see change, I am looking something ajax kind. – Mike Phils Nov 29 '14 at 19:05
  • 1
    Are there any errors reported anywhere? Have you considered adding in alerts (or `console.log()`) to monitor execution? Is the function being called every 250ms? – David Thomas Nov 29 '14 at 19:12
  • https://github.com/HubSpot/offline, or this helpful explanation: http://stackoverflow.com/questions/3181080/how-to-detect-online-offline-event-cross-browser – axel.michel Nov 29 '14 at 19:17
  • Please do not post the same question multiple times. – Sparky Nov 29 '14 at 19:25

0 Answers0