Retain global variables upon browser refresh.

Posted by Vishalneeraj-24503 under JavaScript on 3/23/2018 | Points: 10 | Views : 4649 | Status : [Member] [MVP] | Replies : 1
Hello All,

I have a web application which is built on Node JS platform and fetching data from Sharepoint.
So Node JS is a mediator between UI and SharePoint.
We have used Javascript & jQuery for each and every operation like fetching data from SP, update data to SP and so on..

We have used Kendo grid/popup and creating dynamically HTML tags like
and Kendo Grid columns header & rows and so on..

In our web application, we have taken so many global variables on page and setting them dynamically.
But when we refresh the browser then all these variables get refreshed i.e. we lost values.

Some variables hold true/false values.
Some holds numeric and string values.
Some holds JSON result.
Some holds Object like var obj = {}.
Some holds Array object like var obj = [].
Some holds static messages.

Like in short, every global variables hold some values when logged-in to system and based on these values we manipulate Sharepoint data.

So my requirement is like W?hen user clicks IE browser refresh button, application is supposed to retain on the same page with same data.

Currently when User refreshes the page, the application goes to the login page then again he has to log-in to the system and perform the tasks.

I used localStorage.setItem and localStorage.getItem to check whether user is logged-in and if he/she is logged-in then i am not showing login window to the user. However page is blank because all the variables have lost data.

Do i need to set all variables with localStorage or is there other way to achieve. Because setting each and every variable in each of the function is a vary tedious job.
And how certain this will work or not?

So how to deal with this scenario?

I have tried with localStorage and sessionStorage.


Posted by: Sheonarayan on: 3/25/2018 [Administrator] HonoraryPlatinum | Points: 25

I feel, there are following ways to retain the values even after page refresh

1. Querystring
2. Cookies
3. localStorage
4. sessionStorage

First 2 is tedious to maintain, so you are left with remaining 2. You are already using localStorage and I think that is the way to go.


Sheo Narayan

Vishalneeraj-24503, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response