Page 1 of 1

Error Message when internet not available

Posted: Wed Apr 30, 2014 7:27 am
by Puneet Duseja

Hi,
My application works only when internet connection is available. So when user clicks on any buttons, i need to check if internet is available on the divice and if yes app will work fine and if not give a prompt/error message," Please connect to internet".
Pls let me know how can this be done or is there any default message already?

Thanks


Error Message when internet not available

Posted: Wed Apr 30, 2014 8:08 am
by Kateryna Grynko

Hi Puneet,

You will need to add Offline event handler to each app page. If fires when you lose the Internet connection.


Error Message when internet not available

Posted: Wed Apr 30, 2014 8:38 am
by Puneet Duseja

Hi Katya,
Thanks!
Could you please guide me how can i do that, it would be great if you can share code for the same.


Error Message when internet not available

Posted: Wed Apr 30, 2014 1:23 pm
by Kateryna Grynko

Puneet,

Add Offline event handler: prelocalStorage.setItem("online", "false");/pre
And Online event handler: prelocalStorage.setItem("online", "true");/pre
For all buttons add this Click event handler:pre$('[data-role="button"]').on("click", function(){
if (localStorage.getItem("online") == "false"){
alert("Please connect to internet");
}
});/preThis is to check the variable and display a message if needed. You can add it as custom JS or on page Load event.


Error Message when internet not available

Posted: Thu May 01, 2014 4:26 am
by Puneet Duseja

Thank you!


Error Message when internet not available

Posted: Thu May 01, 2014 5:32 am
by Alex GG

hello!
Im using grids and images instead of buttons...Can I use this code too?
I mean data-role="grid" ?

Thanks!


Error Message when internet not available

Posted: Thu May 01, 2014 6:19 am
by Nikita

Hello,

There isn't "data-role=grid" attribute. In this case you should add this event listener on your image component.