-
Jul 7th, 2020, 06:17 PM
#1
Thread Starter
PowerPoster
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,
-
Jul 7th, 2020, 07:16 PM
#2
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.
-
Aug 8th, 2020, 05:53 PM
#3
New Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|