Global Counter?

  1. 10 months ago
    Edited 10 months ago by Jack T


    Does anyone know if it is possible to have a global counter or a global variable? I would like the actions I do on page 1 to affect my possible actions in page 2 or 3.


    Edit: Found that the counters in the overlay also does not keep their value over pages.

  2. Angelo S

    28 Jun 2018 Administrator

    At the moment, you have to use Javascript for those kind of things.

  3. 4 months ago

    Sorry but I tried with all different ways to define a global variable and seems impossible. could you give a specific example in pubcoder?

  4. Angelo S

    Jan 16 Administrator

    To share data among different pages you should use LocalStorage, be sure to check support in the reader app you will be using.

  5. Thank you a lot @Angelo S for your reply. I have already used localstorage and I have the following problem. Eg. I define in project javascript a global counter variable:
    Now if I want to change its (global) value by eg. clicking a button on a page it seems impossible. I use run Javascript there eg. on tap of a button, event is run javascript and I try to trigger the apearence of a text.
    if (localStorage.counter==2){$("#obj111").show()}
    This seems not to work because for the program localStorage.counter is still 1. (so if in the if I set 1 instead of 2 the object does show)

    Could you explain how I can fix this? I have tried also with page javascript and it seems it is the same.
    I could sum up the problem as follows. if localStorage variable is written on project javascript then every page "sees" it but if I try to adapt its value locally on a page it is impossible.

    Thank you in advance

  6. Ok I managed to do it. but it is very difficult to understand that a variable in local storage defined in the project will not be updated. Maybe a tutorial on how to use html/javascript in pubcoder would be very helpful.

  7. 3 months ago

    Angelo S

    Feb 9 Administrator

    You're not using localstorage the right way. Please check this documentation for further help:

    As for documentation for using javascript in PubCoder, here's the right reference:

    Of course this includes only things specific to PubCoder, it's not intended as a comprehensive JavaScript/HTML/CSS guide...


or Sign Up to reply!