Setting a Session variable and retrieving it using Javascript
Here is my scenario....on my main web page, there are 4 links that will call a second .html page. However, each of these links need to pass a unique value into the second .html page. I'm thinking that using a Session variable is the way to do this. Can this be done using Javascript? If so, I having trouble finding real examples. If not, what is the best way to pass a value into another page. I'm not using .NET or any other programming language.
Thanks,
Re: Setting a Session variable and retrieving it using Javascript
You'll need to use localstorage.
https://developer.mozilla.org/en-US/...w/localStorage
Session is only for one page.
Re: Setting a Session variable and retrieving it using Javascript
Yes it is possible. You can either use document.cookie, window.localStorage or window.sessionStorage.
But window.localStorage and sessionStorage are only supported in modern Browsers.
So, you should check for browser's compatibility before proceeding.
Code:
<script>
function saveVariable()
{
if(typeof(Storage) == "undefined")
{
alert ("local storage not supported by this Broswer");
}
else
{
localStorage ['test'] = 'Saving to local storage'];
}
}
function read()
{
alert (localStorage ['test']);
}
</script>
You can check https://www.emmason247.com.ng/tutori...rage/GGZIGWWZD for more information