[Mobile] Javascript not running when offline

[Mobile] Javascript not running when offline

  

Hello,

I got a upload widget on my mobile screen that needs to be disabled when the user has no internet connection. Since there's no Disabled property on the upload widget i tried running the following javascript:

var uploadsWidgets = document.getElementsByClassName("upload");
for (var i = 0; i < uploadsWidgets.length; i++) {
    uploadsWidgets[i].childNodes[0].setAttribute("disabled","disabled");
}

With internet connection, the javascript runs and disable the widget, but when offline the javascript runs but the widget stays enabled.

Is there any restrictions running javascript while offline? Or is there any other way to disable the widget when offline without having an 'if' in every upload widget that i'm using?


Thanks.


Rafael Battistelo wrote:

Hello,

I got a upload widget on my mobile screen that needs to be disabled when the user has no internet connection. Since there's no Disabled property on the upload widget i tried running the following javascript:

var uploadsWidgets = document.getElementsByClassName("upload");
for (var i = 0; i < uploadsWidgets.length; i++) {
    uploadsWidgets[i].childNodes[0].setAttribute("disabled","disabled");
}

With internet connection, the javascript runs and disable the widget, but when offline the javascript runs but the widget stays enabled.

Is there any restrictions running javascript while offline? Or is there any other way to disable the widget when offline without having an 'if' in every upload widget that i'm using?


Thanks.


Hi Rafael,


When you using javascript offline then you need to include all its library in offline mode.

When you calling in offline mode then they are not able to call their scripts because it is in cloud server.


Thanks,

Rajat Agrawal 


Hi Rajat,

The code you show is pure javascript, not part of any javascript library, it should normally work also when in offline mode.

Also if you include javascript files in your mobile app, these are available locally, no need to have online internet connection for them.


To try and pinpoint the problem you could either:

  •  debug the application on your device
  • debug in the browser and check with the browser dev tools for error messages in the console, or even debug the generated javascript.
  • build in some Info messages inside the for loop, to check if code is actually reached.

Good luck with it!

Regards,

Daniel



Rafael,

Adding to Daniel's answer, I would like to point you that your code just go through a set of elements and disable it.

So, the problem is, probably, in the way you are calling this code.

I would recommend you to use the event from the NetworkStatusChanged block.

This way, when your handler is executed, you can check the network status (IsOnline) and execute your script to disable or enable the uploads.

Cheers.

Eduardo Jauch wrote:

Rafael,

Adding to Daniel's answer, I would like to point you that your code just go through a set of elements and disable it.

So, the problem is, probably, in the way you are calling this code.

I would recommend you to use the event from the NetworkStatusChanged block.

This way, when your handler is executed, you can check the network status (IsOnline) and execute your script to disable or enable the uploads.

Cheers.

Hello Eduardo,

I'm using the 'GetNetworkStatus' action to decide if i should call or not the javascript, in this aspect it's working fine.

As a temporary solution, i'm using the upload widget disabled as default, and if there's internet connection, i'm enabling it, this way is working fine.