Cross-Browser DHTML: A Spork in the Road
October 25, 1998
A Spork in the Road
When considering cross-browser code you must first decide
on a main approach: do you fork the code into two
independent versions, one for each browser; or, do you
write a single version of code which internally adapts to
the browser being used -- sort of a hybrid code, not unlike
the high-school cafeteria's plastic spork. Although
some developers strongly suggest that the spork approach
is the most elegant solution, in truth there are pros
and cons to both schemas.
The basic idea behind forking the code is quite simple.
At the topmost level, you could simply create two wholly
independent DHTML pages, one of which is tuned for Internet
Explorer and the other for Netscape. Visitors to your
site would connect directly to neither page; instead, they
would connect to a "forking page," which detects
their browser and forwards them to the appropriate version.
An example forking page appears below -- it simply
uses JavaScript to evaluate the situation. The primary
advantage to this approach is that it is simple to implement,
assuming you have no troubles writing your DHTML in two
versions, one for each browser. The disadvantages to top-level
forking are several: you must maintain and update two versions
of the page content, bookmarks made by the user
will incorrectly point to the browser-specific page rather
than the forking page, and you will not earn great respect
as a master programmer due to the inelegance of this technique.
A Forking Page: "mysite.html"
<html><head>
<title>MySite Browser Detect</title>
<script language="JavaScript">
<!--
function version()
{ if ((window.navigator.appName.indexOf("Netscape")==0)
& (window.navigator.appVersion.substring(0,1)>="4"))
{ location="mysite_ns.html" }
else { if ((window.navigator.appName.indexOf("Microsoft")==0)
& (window.navigator.appVersion.substring(0,1)>="4"))
{ location="mysite_msie.html" }
else { location="mysite_nodhtml.html" }
}
}
//-->
</script></head>
<body onLoad="version()">
<noscript>
Sorry but this DHTML site requires a browser with JavaScript
support enabled.
</noscript></body></html>
Cross-Browser DHTML: A DOM for all Seasons
Cross-Browser DHTML
Cross-Browser DHTML: Simple Hybrid
|