Frames, Arrays, Dates, and more
What It Does
Note: This page needs to be viewed in frames for this demonstration.
Defining the Frames
<frameset rows="25%,75%" frameborder="0" border="0"> <frame src="about:blank" name="change"> <frame src="tutorial_mixed1_main.html" name="main"> </frameset>
How It Works
Next, a Date object is created. When it is constructed with no parameters, the Date is set to today's local date and time. So, when the getMonth() method is called, it is retrieving the current month's index (starting at 0 for January).
The onload event is set to the function gotoPage. So, when the contents of the window are done loading, the event is triggered. There is only one line in gotoPage, and it changes the contents of the "change" frame depending on what month it is.
If a blank page loads in the top frame, then the script isn't working. If it is working, one of three pages will load in. The color of the page should match with the month as shown below.
Updated: July 24, 2001
To change the page location, overwriting the current history entry, use the location.replace method. This fixes the back button problem. Still refer to the June 09, 2001 update for the "about:blank" suggestion.
Old Way - Example to change the page location, adding a new history entry:
window.frames["change"].location.href = monthLinks[month];
New Way - Example to overwrite history entry:
The location.replace method was implemented in Netscape 3.0 and Internet Explorer 4.0. The example on this page has been tested and works in Netscape 3.04, Netscape 4.74, and IE 5.0.
Updated: June 09, 2001 (*July 24, 2001 - the comments here refer to using location.href)
This section [was*] added to cover a few browser issues that came up while testing this page. The major problem is in loading the top frame to a blank page. A solution is to set the src attribute in the frame tag to "about:blank". This way seems to work, but there still are problems [* with location.href]. To test: open this page (framed version) via a link, and hit the browser back button.
Note: all browser information is for the Windows versions.
The first time back is hit, the top frame loads a blank page. Only after the second time does the top frame load the previous page. Of course, Netscape 3 has other unrelated issues. For example, after hitting the browser refresh, most of the pages at this site will get repainted incorrectly, and "disappear". Also, the page does not adjust properly to fit in the width of the window. This occurs in various screen resolutions.
This version of Netscape also has a problem the first time back is hit: Nothing happens. The second time, the top frame loads the previous page.
Internet Explorer 5.0
IE 5 works well and goes back to the previous page the first time.