Creating the conditional branches for your functional code, once you've sniffed out the browser, can be done a number of ways, many of which you can come up with off the top of your head. But in addition to these, there's a neat trick you should know. The general idea is called conditional commenting. This is the one of the easiest conditional coding techniques imaginable. It works simply: Embed code that uses features specific to newer browsers within the comment tags of older browsers. The net effect will be that older browsers (incapable of running the code) will ignore that section of code, while newer browsers will do the opposite, ignoring the tags and running the code. There's also an enhanced version of conditional commenting. This is a good choice if you're writing primarily for more modern browsers, such as Internet Explorer 5.0 or equivalents. It employs the concept mentioned above, utilising both the old-style comment tags: <!-- comment goes here--> and a newer variation, specific to IE 5: <! With this tag, code can be enabled and disabled for Internet Explorer 5 by toggling with these comment tags: <!-- html src start --><![if ! IE 5]>
I am an object being displayed by a Web page running on some browser other than Internet Explorer 5.
<![endif]>
<!-- [if IE 5]>
I am an object being displayed by a Web page running on Internet Explorer 5.
<![endif]--> You can do a lot more, in the course of scripting, to optimise your application. For instance, it's easy to externalise scripts and even to activate them based on the OOP attributes of screen objects. We'll examine these subjects down the road.






