JavaScript How to retain value of the variable after the page is reloaded? [duplicate] retain value variable,retain variable value in sas,retain variable

This question already has answers here:
Answer:1

You can use localstorage of HTML5.

window.content.localStorage[key]=value; //Saving

window.content.localStorage[key]; //Accessing

delete window.content.localStorage[key]; //Delete

Where KEY = the name of the variable you want to store, and VALUE is the string value you want to save. This only supports saving Strings, but if you need to save an object you can "stringify" the object with JSON.

So you can do something like:

<script type="text/javascript">

function pagereload(){

if(typeof(Storage)!=="undefined")
{
var count=(window.content.localStorage[key])? parseInt(window.content.localStorage[key]): 0;
count++;
window.content.localStorage[key] = count;

var tempTime = count*1000;
var pospond = 50000-tempTime;
setTimeout(function(){window.location.reload()}, pospond);

}
else{
setTimeout(function(){window.location.reload()}, 30000);
}
</script>
Answer:2

You'd better have a look at browser cookie.

http://www.w3schools.com/js/js_cookies.asp

Answer:3

You can store data persistently on the browser using either cookies or Local Storage.

Then, in future pages on the same domain, you can then use javascript to retrieve the prior value. Without using a technique like this to store data locally, each reload of the browser page starts completely fresh.

Your other option is to store the data on the server on behalf of the current user. When the value is changed in the client, you would make an ajax call to the server so the new value can be stored on the server. You can then either retrieve the value from the server with ajax in a future page or the server can place the current value into the page each time it is requested. You would need some method of identifying the current user (often a user login) so the server could retrieve the proper user's data.

Answer:4

I want to visualize some timeseries data in the browser with jqplot. My problem is, that the x-axis values overlay and aren't readable. Therefore, the zoom function would be very useful. But it ...

I want to visualize some timeseries data in the browser with jqplot. My problem is, that the x-axis values overlay and aren't readable. Therefore, the zoom function would be very useful. But it ...

I want a hidden div on owl carousel. Please Help me . i am calling all css file from owl carousel . Here is my calling css file <link rel="stylesheet" href="<?php echo ...

I want a hidden div on owl carousel. Please Help me . i am calling all css file from owl carousel . Here is my calling css file <link rel="stylesheet" href="<?php echo ...

Does Angular sanitize all data when it gets rendered in the DOM automatically? ie, would this be safe: // using 'ngSanitize' angular.module('app', ['ngSanitize']); // somewhere in controller $http....

Does Angular sanitize all data when it gets rendered in the DOM automatically? ie, would this be safe: // using 'ngSanitize' angular.module('app', ['ngSanitize']); // somewhere in controller $http....

I'm trying to implement loading animation of chart using transition animations by adding rows and refreshing the chart. But it behaves completely differently from what I expect. Here is the Fiddle ...

I'm trying to implement loading animation of chart using transition animations by adding rows and refreshing the chart. But it behaves completely differently from what I expect. Here is the Fiddle ...