Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Session Variables With Javascript

  1. #1
    Join Date
    Jan 2005
    Posts
    498
    Rep Power
    0

    Default Session Variables With Javascript

    Is there anyway I can create a variable that will be able to move from page to page within my website using Javascript? Based on my understanding javascript releases variables after the page has finished loading or rather after the script has finished running so i was wondering if there is a way to emulate a session variable using javascript.
    Notorios
    That Which Is Not Defined Is Infinitely Great
    Google The Search Engine Of The Gods

  2. #2
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    A quick scan of the web shows that it can't do it, but can do cookies.

  3. #3
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    You would have to use cookies to keep info between pages with javascript.
    Or use hidden forms.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  4. #4
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Default

    It would be a lot less programming if you used a web programming language like asp or php. They handle session better than javascript ever will and you dont need cookies to do it.
    'If we're supposed to work in Hex, why have we only got A fingers?'

    Follow Me: @psybuck2002us

  5. #5
    Join Date
    Jan 2005
    Posts
    498
    Rep Power
    0

    Default

    Thanks. Well as i thought, can't be done. I guess cookies will have to do. I know that asp and php are the way to go but its for an assignment and we dont get marks for asp, php or anything like that cuz it not in the outline. So cookies will have to do. Thank you.
    Notorios
    That Which Is Not Defined Is Infinitely Great
    Google The Search Engine Of The Gods

  6. #6
    Join Date
    Jan 2005
    Posts
    3,151
    Rep Power
    0

    Default

    whats wrong with cookies?

    use the javascript and set the cookie.. then on load use javascript to read the cookie.

    State saved.

  7. #7
    Join Date
    Jun 2003
    Posts
    159
    Rep Power
    0

    Default session object

    look up the session object

    session.data

    Object providing space for run-time user data (user cache).

    Syntax
    session.data
    session.data.propertyName
    session.data[propertyNameString]

    Example
    session.data.lastclick = new Date();
    session.data.language = "en";

    res.write(session.data);
    TransientNode session

    for (var p in session.data)
    res.writeln(p + ": " + session.data[p]);
    lastclick: Fri Jul 12 14:08:20 CEST 2002
    language: en

    res.write(session.data.lastclick);
    Fri Jul 12 14:08:20 CEST 2002

    res.write(session.data["language"]);
    en
    I have within me the blood of kings....take me to the leader of your world.

  8. #8
    Join Date
    Jan 2005
    Posts
    498
    Rep Power
    0

    Default

    thanx for that editor gonna look into that
    Notorios
    That Which Is Not Defined Is Infinitely Great
    Google The Search Engine Of The Gods

  9. #9
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by editor View Post
    look up the session object
    Are you talking java or javascript? There is no session object in javascript. And yes, I did a search via google and also my favourite javascript sites.

    For my many years of coding with javascript, I have never heard of a session object.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  10. #10
    Join Date
    Apr 2008
    Posts
    11
    Rep Power
    0

    Default

    But you can emulate that easy.

    Create a frameset and one frame in it.
    In the frameset you store your variables and load from there the frame's uri.

    That's it.

    Attached a quick and dirty example.

    page2.html I copied from a website as a proof of concept. Fill on page1 and page2 data in and they will persist until you leave the frameset. That gets as close to a session environment as you can get. You have to change only the <body> statement and call when you change the uri top.changeDoc with the uri as parameter.

    I show in that example two ways:

    1) Iterate through the forms and within the forms through it's elements
    2) Traversing through the dom

    (You have on page1 a button to initiate each and the results are identical.)

    To show the outcome I added a small second frame that contains a textarea which I throw the stored data into for show.

    Throw the unziped 4 html files into a directory or the desktop and open shell.html (which does all the work) in your favorite browser. I tested it in Firefox and the other browser.

    It's not documented (I had not the time) and is naturally copyLeft (you can do with it whatever you want and don't need to mention me as the author).

    Btw. Why can't I upload rar files, only zips?

    günter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •