//The source for this info is from: http://www.builder.com/Authoring/Dhtml/ss03c.html
Writing browser-specific HTML in JavaScript
Once you've detected the browser version, you often need to
conditionally write out HTML markup that's appropriate for the
particular browser version. That can get to be a lot of
document.write() statements and version checks.
To save a bit of typing, use the first of the two simple functions
below to write out a string. This function has two advantages
over document.write(): it has a shorter name so it saves
typing, and it writes out the code only if the current browser
version is greater than or equal to the second (optional)
parameter and less than or equal to the third (also optional)
parameter.
Likewise, if you're concatenating a long string of markup that
depends on the browser version and you want to optionally
insert some HTML markup into the string, you can use the
second function to return the string or "", depending on the
browser version.
Note that both functions rely on the is global object created in
"The ultimate client sniffer."
Function 1:
// --------------------------------
/* convenience function to save typing out document.write("STRING");
if optional second argument version passed in, only write if >= that
version; if optional third argument maxVersion passed in, only
execute if <= that version; */
function dw(str, version, maxVersion) {
if ( ((dw.arguments.length < 3) || (is.major <= maxVersion))
&& ((dw.arguments.length < 2) || (is.major >= version)))
document.write(str)
}
// --------------------------------
Function 2:
// --------------------------------
/* string version:
convenience function to return str or "" depending on version;
if optional second argument version passed in, only return str if >=
that version; if optional third argument maxVersion passed in, only
return str if <= that version; */
function sv(str, version, maxVersion) {
if ( ((sv.arguments.length < 3) || (is.major <= maxVersion))
&& ((sv.arguments.length < 2) || (is.major >= version)))
return str;
else return ""
}
// --------------------------------
Obviously, these two functions deal only with version number,
but you could extend them to check browser vendor as well. Go
for it.