| ★ wanayoo — archive 1999 http://webtools.com/story/dhtml/TLS19980813S0003 | Nouvelle recherche | Portail wanayoo |
![]() |
![]() |
Free E-mail
|
![]() |
|
||||||||||||||||||
![]() |
||||||||||||||||||
|
Events In Action Once you've defined an event, you can use it through JavaScript anywhere in the HTML page. Here's where your imagination can run wild. An event's text can be plain text, HTML, or whatever you want to put into it. To actually show the text for a defined event, write the following line of JavaScript exactly where you want the text to appear on your page (myvar is the variable name you chose): document.writeln(myvar.content);
You can also include the line in the same JavaScript statement you wrote for the object and event definitions -- which is what I prefer, for simplicity's sake. In addition, you can specify some descriptive text in the document.writeln line that will always precede or follow the event text (see the sidebar "Calendar Of Events" below). A couple of examples here will demonstrate the rotator's potential, and there are even more on the Windows Magazine website. The sidebar "Calendar Of Events" shows an example of a simple calendar. If someone visits the page on a day defined by one of the events, that event will automatically be displayed. On a day with no matching event, no text will be displayed because the default text for the rotator is an empty string. You can also use the rotator text to modify the look of elements on the page. That is, the text defined by the rotator variable isn't directly shown to the user, but makes some change to the way the page is displayed. The sidebar "Web Pages In The Moonlight" demonstrates this approach by changing a page's background color depending on the time of day. The rotator's default value specifies a white background color, which is what the page uses during daylight hours. For an hour starting at 5 a.m. (05:00) and 6 p.m. (18:00), the page is light gray; in the late evening and early morning, the page is dark gray. I had actually planned to show an example that combined the content rotator with some Dynamic HTML (DHTML), but after a few hours of experimentation, I found it was simpler to use some well-chosen JavaScript and style sheets. The Microsoft and Netscape models for share a similar goal, but are extremely different in implementation. Even the simplest examples of DHTML turn into a case of writing a Microsoft version, writing a Netscape version, then using JavaScript to decide which one you need when the page loads. Yuck. But stay tuned: Next month I'll show you how to serve up new content every time a visitor refreshes your page.
|
|
|||||||||||||||||
| ||||||||||||||||||
| |||||
![]() |
|