2

I have an HTML link that links to an external site. I want to be able to add a dialog message when the user taps on the link and no internet connection is available. I want to be able to do this using HTML and javascript.

See this example of what I am trying to achieve. Thanks. https://www.dropbox.com/s/r5qgxgjuusr8o1n/2014-07-15-15.20.28.png

2
  • Why put that in your page? That's already built-in functionality of your browser (which can also give a much more detailed error message)
    – Bergi
    Commented Jul 15, 2014 at 22:17
  • This is for as Adobe DPS HTML article, my issue is when the device isn't connect to the internet and the user taps on the links no error message is display. Which is an automatic rejected of my app from Apple. Commented Jul 15, 2014 at 22:36

1 Answer 1

2

You could use navigator.onLine; to know whether the browser is in online or offline mode.

The onLine property is supported in all major browsers.

you can execute a javascript function on click of your link that check this property.

refer here for documentation

2
  • Using the link for the possible duplicate, you could provide an alternative method to this as well. :) Commented Jul 15, 2014 at 21:31
  • This is the correct way to do it. Just run some sort of timer function or urn javascript on click. Just use: if navigator.onLine; {PERFORM A FUNCTION} else {PERFORM ANOTHER FUNCTION} Worked nicely for me :)
    – dwinnbrown
    Commented Jun 11, 2015 at 10:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.