Cookies and Frames

Sometimes, I just don’t have the time to blog even if I have something interesting to write about. I also try to only update with relevant posts. FYI.

I spent last week fixing up some JavaScript on a site that has frames. While I have plenty of past experience that tells me using frames is bad, this one took the cake. Here’s why.

  1. Everything is dandy until you have to have a frame access the other’s variables. This did not go smoothly in IE7. I was very flustered with that since it was “supposed” to work.
  2. JavaScript functions need to be placed globally. This was a problem when I had two frames work closely together until one frame got logged out by the system and popped to the login screen (complete with missing function declarations)!!

The moral of that story is not to use frames!

Also, I got to play with cookie manipulation in JavaScript. This was new to me. Which, by the way, was the eventual solution I used to have my two frames pass data back and forth. Anyway, cookies are WEIRD in JavaScript.

They are accessed through the “property” document.cookie. However, unlike regular properties, when you assign a cookie, you use a different format  than when you output it. In other words, assignment looks like:

document.cookie = “some cookie string that’s gibberish I don’t want to explain now”

Whereas reading the cookie (document.cookie) returns the data values for *all cookies* for the current domain. Oh, and in one giant semi-colon delimited string. Annoying.

My advice on using cookies in JavaScript? Write a class that manages them first.