Results 1 to 3 of 3

Thread: Setting a Session variable and retrieving it using Javascript

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2004
    Location
    Southern California
    Posts
    5,034

    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,
    Blake

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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.

  3. #3
    New Member
    Join Date
    Jul 2020
    Posts
    9

    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
  •  



Click Here to Expand Forum to Full Width