Frames. I really don’t like frames. In fact, I pretty much hate them. I know they have some value someplaces, but I’ve had some bad, unplesant and not-fun experiences working with them in the past. So I hate them.
That said, I just ended up working on a framed page. Here is the page
----------------------
|parent frame |
| ------------------ |
| | "top" | |
| | | |
| | | |
| | | |
| ------------------ |
| ------------------ |
| | "bottom" | |
| ------------------ |
|--------------------|
The frame named “top” was visible to the user. It was a reloading screen that never reloaded. Just some text and a progress graphic. The frame “bottom” was the page that checked against the server on progress. Not the way I would have done this particular setup, but that’s neither here nor there. It’s what I had to work with.
I had a script on “top” that kicked off a countdown once the page (that’s the page “top”) loaded.
Since “top” never reloaded, the countdown wasn’t reset in any way. But I needed it reloaded whenever “bottom” reloaded.
In short, I needed “bottom” to talk to the JavaScript variables and functions on “top”. I kept running into problems getting this to work. Maybe because I’m dense, maybe because I’m not a super-genius like I think I am, or just maybe because I try and avoid frames like the plague.
Well, I found the solution was pretty simple. JavaScript communicates across frames fairly easy. To do so, you have to refrence the frame. You can do this by the notation top.FRAMENAME.
So I’m in the top, hidden frame. I need to reference a variable in “bottom”, and include that in a timeout.
clearTimeout(top.top.TIMEOUTVARIABLENAME);
That will clear the timeout I set in the other frame.
top.top.TIMEOUTVARIABLENAME = setTimeout("timeOut()",top.top.TIMEVARIABLE);
This sets the timeout variable in the other window using a number I set in the other window. I’m referencing variables remotely, across frames.
The top.top part is odd looking because one of the frames name is top. So the lesson here is don’t name a frame top becuase you’ll end up with top.top. Which is goofy.
Tagged As Javascript
Comments are Open (0)
Posted at 01:09 PM