Session variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Enoch Chan

    #1

    Session variable

    I would like to set a Session variable to a value. In Vbscript it should be

    Session("ZoomVa lue")=500

    How can I set this session variable by using Javascript?

    Thanks


  • Jim Ley

    #2
    Re: Session variable

    On Tue, 12 Oct 2004 20:56:52 +0800, "Enoch Chan" <sil_fx@hotmail .com>
    wrote:
    [color=blue]
    >I would like to set a Session variable to a value. In Vbscript it should be
    >
    >Session("ZoomV alue")=500
    >
    >How can I set this session variable by using Javascript?[/color]

    Session.ZoomVal ue=500

    Jim.

    Comment

    • Robert

      #3
      Re: Session variable

      "Enoch Chan" <sil_fx@hotmail .com> wrote in message news:<ckgkam$hv h4@imsp212.netv igator.com>...[color=blue]
      > I would like to set a Session variable to a value. In Vbscript it should be[/color]


      What do you mean by session variable?

      Javascript has global variables. You can access global variables from
      any child frame or child window.

      Javascript has session cookies. You can save small amount of data in a
      cookie. I have had problems with session cookies in IE and do not use
      session cookies any more. Session cookies are cookie that do not
      include a time value. Instead, I set an expiration time on the cookies
      I create.

      I suggest using an existing set of cookie routines. The
      document.cookie can contain existing cookies.



      ~kaeli~ has developed some cookie code. You may view it in this
      article:


      ..1af96c2a4f8ab c94989dcc%40nnt p.lucent.com

      Also, ~kaeli~ reports that:
      There's some even better code that sets more cookie properties like
      domain, secure, path, etc here.




      I wrote a short program for verifying cookies will work on a site.
      The cookie code was taken from:
      Functions from Using HTML 4, Java 1.1, and JavaScript 1.2:
      Complete. Definitive. Invaluble.
      by Eric Jim O'Donnell, et al.
      and from the Netscape develper's site.

      Robert

      Here is my cookie testing
      code:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html;
      charset=windows-1252">
      <title>Rememb er by cookie</title>


      <script type="text/javascript">


      // Sets cookie values. Expiration date is optional
      //
      function setCookie(name, value, expire) {
      document.cookie = name + "=" + escape(value)
      + ((expire == null) ? "" : ("; expires=" + expire.toGMTStr ing()))
      }


      function getCookie(Name) {
      var search = Name + "="
      if (document.cooki e.length > 0) { // if there are any cookies
      offset = document.cookie .indexOf(search )
      if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie .indexOf(";", offset)
      // set index of end of cookie value
      if (end == -1)
      end = document.cookie .length
      return unescape(docume nt.cookie.subst ring(offset, end))
      }
      }
      }

      function deleteCookie(na me,path,domain) {
      if (getCookie(name )) document.cookie = name + "=" +
      ( (path) ? ";path=" + path : "") +
      ( (domain) ? ";domain=" + domain : "") +
      ";expires=T hu, 01-Jan-70 00:00:01 GMT";
      }

      function registerCookie( cookieName,cook ieValue) {
      var today = new Date()
      var expires = new Date()
      expires.setTime (today.getTime( ) + 1000*60*60*24*3 65)
      setCookie(cooki eName, cookieValue, expires)
      }
      </script>

      <body>
      <p>Let's see if we can set then read a cookie


      <script type="text/javascript">
      document.write( "when on (document.url) " + document.URL);
      document.write( "</p>");

      var all = "I hope this cookie doesn't crumble.";

      document.write( "<p>");
      document.write( "document.cooki e before deleteCookie = "
      + document.cookie + "<br><br>") ;
      deleteCookie("m ycookietry");
      document.write( "document.cooki e after deleteCookie= "
      + document.cookie + "<br><br>") ;

      registerCookie( "mycookietry",a ll);

      document.write( "document.cooki e after registerCookie = "
      + document.cookie + "<br><br>") ;

      theMessage = getCookie("myco okietry");
      document.write( "theMessage = " + theMessage + "<br>");
      document.write( "</p>");
      </SCRIPT>
      </body>
      </html>

      Comment

      • Dr John Stockton

        #4
        Re: Session variable

        JRS: In article <c6bb75ff.04101 21217.7bb9e6ca@ posting.google. com>,
        dated Tue, 12 Oct 2004 13:17:40, seen in news:comp.lang. javascript,
        Robert <rccharles@my-deja.com> posted :
        [color=blue]
        >function registerCookie( cookieName,cook ieValue) {
        > var today = new Date()
        > var expires = new Date()
        > expires.setTime (today.getTime( ) + 1000*60*60*24*3 65)
        > setCookie(cooki eName, cookieValue, expires)
        >}[/color]

        function registerCookie( cookieName, cookieValue) {
        var D = new Date()
        D.setFullYear(D .getFullYear() + 1)
        setCookie(cooki eName, cookieValue, D)
        }

        makes more sense.

        In the original code, expires = new Date(0) would be better; it's
        generally worth spending a character to save determining a date/time
        which will not be used.

        It seems that in most books the code is not good.

        In that context, the final D is used in D.toGMTString() - that format is
        undefined in ECMA-262, and in my system does not comply with the
        apparent specification for a cookie date string. But the interpretation
        of cookie date strings is probably liberal enough, at least for the time
        being.

        It would have been smarter to follow the US FIPS for cookie dates; that
        would have given AIUI all the advantages of ISO 8601 without being
        embarrassingly foreign.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        Working...