window.location & cookies?

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

    #1

    window.location & cookies?

    I have an application that works almost all of the time but there is an
    inconsistent error with some browsers (some Mac, some PC). It seems that
    the cookie won't get written before the redirect. If I turn on cookie
    prompting my computer will stall just after this cookie is written (if it's
    even written) *MOST* of the time.

    setCookie("FC2" , escape(escape(g etCookie("FC")) ), "", "/",
    ".lacs.utexas.e du", false);
    window.location = "http://www.lacs.utexas .edu/logon.asp?step= 2";

    I can't use Server-Side Scripting, as JavaScript is necessary to write the
    cookie (ASP and the server that writes the original cookie I'm using don't
    agree about URL encoding). Even the ASP redirect won't work once the
    JavaScript has been written to the client.

    Is there a better solution than window.location or can I stick the
    window.location further down in the code, perhaps giving the client time to
    finish writing the cookie? Do you think this is even the problem?

    Sorry if this doesn't make sense, this has been a frustrating problem for
    the past week.

    --
    Mike


  • changed

    #2
    Re: window.location & cookies?

    "changed" <changed@change d.com> wrote in message
    news:<bk4kmd$on p$1@geraldo.cc. utexas.edu>...

    setCookie("COOK IE", VALUE, "", "/", ".domain.co m", false);

    window.location = "http://www.domain.com/logon.asp?step= 2";

    Okay, I've made some progress in tracking down the problem but I don't have
    a good solution. It seems that the cookie isn't populating on slower
    machines before the redirect takes place (and thus the cookie never
    populates?).

    If I move the window.location statement further down it greatly increases
    the chance of success.

    If I get rid of the window.location statement and use an HREF, it works
    100%.

    How can I use a JavaScript redirect and maintain the 100% functionality
    rate?

    THANKS!!!

    --

    Mike


    Comment

    • kaeli

      #3
      Re: window.location &amp; cookies?

      In article <bk52un$7l3$1@g eraldo.cc.utexa s.edu>, changed@changed .com
      enlightened us with...[color=blue]
      >
      > How can I use a JavaScript redirect and maintain the 100% functionality
      > rate?
      >[/color]

      In a while (true) loop, keep trying to read the cookie. Once you can
      read it, break out, then redirect.

      -------------------------------------------------
      ~kaeli~
      Hey, if you got it flaunt it! If you don't, stare
      at someone who does. Just don't lick the TV screen,
      it leaves streaks.


      -------------------------------------------------

      Comment

      • changed

        #4
        Re: window.location &amp; cookies?

        "kaeli" <infinite.possi bilities@NOSPAM att.net> wrote in message
        news:MPG.19cfd7 67658721a198984 c@nntp.lucent.c om...[color=blue]
        > In article <bk52un$7l3$1@g eraldo.cc.utexa s.edu>, changed@changed .com
        > enlightened us with...[color=green]
        > >
        > > How can I use a JavaScript redirect and maintain the 100% functionality
        > > rate?
        > >[/color]
        >
        > In a while (true) loop, keep trying to read the cookie. Once you can
        > read it, break out, then redirect.[/color]

        I think I found the problem. It was a timing issue, but it wasn't strictly
        JavaScript. It does not appear wise to write cookies with ASP and
        JavaScript in the same page request if those cookies are to be used
        immediately afterwards. Something like that anyway... :)

        --
        Mike


        Comment

        • kaeli

          #5
          Re: window.location &amp; cookies?

          In article <bk7r5u$hqb$1@g eraldo.cc.utexa s.edu>, changed@changed .com
          enlightened us with...[color=blue]
          >
          > I think I found the problem. It was a timing issue, but it wasn't strictly
          > JavaScript. It does not appear wise to write cookies with ASP and
          > JavaScript in the same page request if those cookies are to be used
          > immediately afterwards. Something like that anyway... :)
          >[/color]

          Oh, no, it isn't. Server-side script cookies (ASP, JSP, ColdFusion) are
          written via the headers, then stored a short time later if they are not
          session cookies (i.e. they must be given an expiration date). In fact,
          if you write the cookies via server-side script, then use a javascript
          redirect that doesn't pass the headers, like location.replac e(), you'll
          lose the server-side cookies.
          Javascript writes cookies immediately to the user's cookie area.
          I've had problems combining the two before as well.

          -------------------------------------------------
          ~kaeli~
          Hey, if you got it flaunt it! If you don't, stare
          at someone who does. Just don't lick the TV screen,
          it leaves streaks.


          -------------------------------------------------

          Comment

          Working...