|
||
| Inside Technique : A-B-C-DHTML Behaviors IE5 introduces us to an idea, the DHTML Behavior. This is Microsoft's newest method of incorporating Dynamic HTML (in particular the scripting aspect of it) into a Web Page. Unlike other methods of including script, DHTML Behaviors do not use a <script> tag. Instead, they are assigned using a CSS attribute called (what else) 'behavior'. This 'behavior' is given the URL of a file which contains the actual behavior. While the advantages of this may not seem apparent at first, they become obvious with use. The biggest advantage comes in the browser detection code, or lack there of. If you've written scripts for any of the 4.x browsers, you know what I'm talking about. Now, you could've tried to write cross-browser, but it took a lot more effort, and most developers ended up making different pages for different browsers (including 3.x and 2.x). DHTML Behaviors solve this problem. Since at this time, only IE5 supports a 'behavior' attribute to CSS, any DHTML Behaviors will only be parsed and used by IE5, all other browsers will ignore them. Not only does this solve the problem of scripting for NN5 or IE5, but it also solves the problem of scripting for 4.x and 3.x and so on. How? Because you can build a page for the lowest browser version, then add behaviors to it. All the browsers can see the regular content and IE5 can see the DHTML Behaviors. A second advantage is that they are hundreds of time eaisers for every day HTML authors to use. So, lets get down to work. 'Behavior' should be treated like a regular CSS attribute and can be assigned inline, globally to a tag or globally to a class. Here is the syntax: behavior: url(file.htc);
The file.htc is the name of the file that contains the DHTML Behavior (which, FYI, is the second generation of IE4 Scriptlets). So the big part of the DHTML Behavior is in that file. It is important to note that this file will be written in XML and it is very picky about closing tags. Next we examine both the markup to create the behavior and how to work with the behavior's properties and events. |
Page 1:A-B-C-DHTML Behaviors
Page 2:Introducing Behaviors
© 1997-2000 InsideDHTML.com, LLC. All rights reserved.