Hi, I could really need some help on this one!
My script loses it's memory at some point, can you find why?

This script is supposed to
A) detect the visitors OS
B) Determine wether it's IE4+, NS4+ or whatever below version 4
C) Load the appr .js files depending on detected browser.

This is what it does and what happens:

When it's IE4+ on 32 bit OS it should load one ext.js and write a IE-navigation from another ext.js

When it's NS4+ on 32 bit OS it should load two other ext.js and write a NS-navigation from another ext.js

When it's "Something else" it should load one empty ext.js and write a standard-navigation from an ext.js

I've got a simpler version at my site right now that only differs between IE4+ and "Something else" and this works great.

My problem is that now, when I took NS4+ into the equation this happens:

It recognises NS4+ on 32 bit OS all the way through.

It recognises "Something else" all the way through.

It recognises IE+ on 32 bit OS in choosing ext navscript and loadscript but loses it when it comes to the navigation.

The really wierd thing is that if I comment out the NS parts, It recognises IE4+ all the way through...

Where have I gone wrong??? At this point I'm totally lost and feel like an idiot...

Here is the script, Its commented where it works and not, there is also a lot of alerts in there, that plus "theBrowser" is just so I can see where it loses it.

You can also try it on an example page at:

I would really like some help on this...
Thanx Dan, Sweden


/* ----------------------------------------------------------------
sniffing code to detect for IE4 or better on either Windows NT or 95
or NS4+ on either Windows NT or 95 and the load the appropriate
external scripts for the visiting browser
---------------------------------------------------------------- */

var sAgent = navigator.userAgent

var bIs95NT
= sAgent.indexOf("Windows 95") > -1
&#0124; &#0124; sAgent.indexOf("Windows NT") > -1
&#0124; &#0124; sAgent.indexOf("WinNT") > -1
&#0124; &#0124; sAgent.indexOf("Win95") > -1
&#0124; &#0124; sAgent.indexOf("Win32") > -1
&#0124; &#0124; sAgent.indexOf("Windows 98") > -1
&#0124; &#0124; sAgent.indexOf("Win98") > -1
alert("32bit OS is '"+ bIs95NT +"' .");
//Works OK

var bIsIE4
= sAgent.indexOf("MSIE") > -1
&& sAgent.indexOf("4") >= 4
&& sAgent.indexOf("b1") <= -1
&& sAgent.indexOf("p1") <= -1
var bIsIE432 = bIs95NT && bIsIE4
alert("Browser IE4 + on 32 bit OS is '"+ bIsIE432 +"' .");
//Works OK

var bIsNS4
= sAgent.indexOf("MSIE") <= -1
&& sAgent.indexOf("4") >= 4
var bIsNS432 = bIs95NT && bIsNS4
alert("Browser NS4 on 32 bit OS + is '"+ bIsNS4 +"' .");
//Works OK

var theBrowser
if (bIsIE432) theBrowser = "MSIE 4 på 32 bit OS";
if (bIsNS432) theBrowser = "Netscape 4 på 32 bit OS";
else theBrowser = "IE under 4 eller NS under 4";
alert("Browser is '"+ theBrowser +"' .");
//Forgets that it is IE4+

var theNavigation
if (bIsIE432) theNavigation = "navstyle.js";
if (bIsNS432) theNavigation = "nsmenu.js";
else theNavigation = "stdlink.js";
alert("Chosen navigation is '"+ theNavigation +"' .");
//Forgets that it is IE4+

var theNavscript
if (bIsIE432) theNavscript = "navscr.js";
if (bIsNS432) theNavscript = "menu.js";
else theNavscript ="noload.js"
alert("Chosen navscript is '"+ theNavscript +"' .");
//Works OK

var theLoad
if (bIsIE432) theLoad = "noload.js";
if (bIsNS432) theLoad = "menuload.js";
else theLoad ="noload.js"
alert("Chosen onloadscript är '"+ theLoad +"' .");
//Works OK

document.write('<SCR'+'IPT SRC="' + theNavscript + '"></SCR'+'IPT>');
document.write('<SCR'+'IPT SRC="' + theLoad + '"></SCR'+'IPT>');
document.write('<SCR'+'IPT SRC="' + theNavigation + '"></SCR'+'IPT>');
//Works OK

***********THE END...***************