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

elixenide
  • 44,308
  • 16
  • 74
  • 100
Automator21
  • 647
  • 2
  • 7
  • 11
  • 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 Jul 15 '14 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. – Automator21 Jul 15 '14 at 22:36

1 Answers1

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

faby
  • 7,394
  • 3
  • 27
  • 44
  • Using the link for the possible duplicate, you could provide an alternative method to this as well. :) – Brett Weber Jul 15 '14 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 Jun 11 '15 at 10:52