DanEnright.com


I wanted to serve documents containing DHTML to version 4.0 (and later) browsers, while also serving non-DHTML pages to version 3.0 (and earlier) browsers. These scripts are the result of my research. Special thanks go out to the folks at Macromedia and DreamWeaver, Nick Heinle (of "Designing with Javascript" fame), A List Apartnik members warwick.poole, Gabriel Reguly, & Larry Lyons, Dori Smith - author of Java|JavaScript for the WWW: Visual QuickStart Guide (Peachpit Press), and John Kerkhoven.

First, here's something I learned about File Naming and how it affects these scripts. Since my files are hosted on LINUX and BSD machines, the idea of using case to differentiate between files is ingrained. To keep track of the two files I was serving, I named the version 3, "file.html" and the version 4, "File.html." This worked in every browser except MSIE 4, which ignored the difference in case and treated them both as file.html - which was attempting to load itself recursively, via javascript. Which MSIE 4 wouldn't allow, loading blank.html, instead.

I've since changed the naming scheme to file.html and file1.html, and the scripts work as expected. That said...


Here's very elegant solution from Dori, it's based on the version of javascript the targeted browsers understand. Here's a working example.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript1.2">
<!--
document.write (' <FRAMESET ROWS="100%,*" FRAMEBORDER=NO BORDER=NO MARGINHEIGHT=5 MARGINWIDTH=5> <FRAME SRC="file1.html" SCROLLING="AUTO"> <NOFRAMES> <BODY> </BODY> </NOFRAMES> </FRAMESET> ');
//-->
</SCRIPT>

Same idea, extra code.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
if  ((bName  ==  "Netscape" &&  bVer >= 4)  ||
(bName == "Microsoft Internet Explorer" &&  bVer >= 4))  br = "n4";
else br = "n2";

if  (br == "n4") document.write (' <FRAMESET ROWS="100%,*" FRAMEBORDER=NO BORDER=NO MARGINHEIGHT=5 MARGINWIDTH=5> <FRAME SRC="file1.html" SCROLLING="AUTO"> <NOFRAMES> <BODY> </BODY> </NOFRAMES> </FRAMESET> ');
//-->
</SCRIPT>


warwick.poole's version of the script, parts of which I used in the previous script. His uses two different sources for the framesets - one for each browser version, so this requires a frameset page, as well as the two content pages.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
if (bName == "Netscape" && bVer <= 3) ver = "version3";
else if (bName == "Netscape" && bVer >= 4) ver = "version4";
else if (bName == "Microsoft Internet Explorer" && bVer >= 4) ver = "version4";
else if (bName == "Microsoft Internet Explorer" && bVer <= 3) ver = "version3";
if (ver == "version3") document.write ('Insert your version 3 frameset here');
else if (ver == "version4") document.write ('Insert your version 4 frameset here');
//-->
</SCRIPT>


My adaptation of warwick.poole's script.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
if (bName == "Netscape" && bVer <= 3) ver = "version3";
else if (bName == "Netscape" && bVer >= 4) ver = "version4";
else if (bName == "Microsoft Internet Explorer" && bVer >= 4) ver = "version4";
else if (bName == "Microsoft Internet Explorer" && bVer <= 3) ver = "version3";

if (ver == "version4") document.write (' <FRAMESET ROWS="100%,*" FRAMEBORDER=NO BORDER=NO MARGINHEIGHT=5 MARGINWIDTH=5> <FRAME SRC="file1.html" SCROLLING="AUTO"> <NOFRAMES> <BODY> </BODY> </NOFRAMES> </FRAMESET> ');
//-->
</SCRIPT>


Nick Heinle's script (slightly modified) which started it all.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
if (bName == "Netscape" && bVer >= 4) br = "n4";
else if (bName == "Microsoft Internet Explorer" && bVer >= 4) br = "n4";
else br = "n2";

if (br == "n4") {
document.write (' <FRAMESET ROWS="100%,*" FRAMEBORDER=NO BORDER=NO ');
document.write (' MARGINHEIGHT=5 MARGINWIDTH=5> ');
document.write (' <FRAME SRC="file1.html" SCROLLING="AUTO"> ');
document.write (' </FRAMESET> ');
}
//-->
</SCRIPT>

 

These next scripts use window.location, so the visitor can't use their back button to navigate - I borrowed from these, too.

The first is a script John sent me, courtesy InfoDial - Javascript MSIE Browser Dectection

NOTE: Gabriel Reguly pointed out, you can avoid the "back button redirect" problem by replacing window.location with window.replace.

<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--
var ver = navigator.appVersion;
     if (ver.indexOf("MSIE") != -1)
     {
          window.location.href="NOTmsie.htm"
     }else
          window.location.href="YESmsie.htm"
// -->
</SCRIPT>

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
if ((bName == "Netscape" && bVer >= 4) ||
(bName == "Microsoft Internet Explorer" && bVer >= 4)) br = "n4";
else br = "n2";

if (br== "n4") {
window.location.href = "file1.html";
}
//-->
</SCRIPT>


or


<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
bName = navigator.appName;
bVer = parseInt(navigator.appVersion);
if ((bName == "Netscape" && bVer >= 4) ||
(bName == "Microsoft Internet Explorer" && bVer >= 4)) br = "n4";
else br = "n2";

if (br== "n4") {
window.replace = "file1.html";
}
//-->
</SCRIPT>


Same idea, less code, requires a "hosting" document.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
if (navigator.appVersion.indexOf('4.0') != -1) {
window.location.href = 'file1.html';
}
else{
window.location.href = "file.html";
}
//-->
</SCRIPT>


or


<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--
if (navigator.appVersion.indexOf('4.0') != -1) {
window.replace = 'file1.html';
}
else{
window.replace = "file.html";
}
//-->
</SCRIPT>


Larry Lyons passed along this tip, " I thought you might be interested in this browser detect script. It looks for HTML 4.0 capable browsers , then if its Netscape or IE:

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript">
<!--

if (document.layers) {n=1;ie=0}
if (document.all) {n=0;ie=1}

//-->
</SCRIPT>

"These two lines simply set up browser detection. The first of these says that if the DOM uses layers, then it must be Netscape 4+, and assigns 1 (or true) to the variable n - to be used in later functions. The next line checks to see if the browser uses the IE approach to the DOM, if so N is set to 0 or false while the ie variable is set to 1 or true.

"I go this approach from Jeff Rule of the Discovery Channel. He's recently written an excellent DHTML book called Dynamic HTML: THe HTML Developer's Guide (Addison Wesley)."



Notice any errors or have any additional scripts? drop me a line and let me know!


javascript I Ching misc. stuff   privacy statement

Dan Enright    dan@DanEnright.com    (570) 487-3155    Blakely, PA