Connecting Tech Pros Worldwide Forums | Help | Site Map

nested if question

Jeff Maestas
Guest
 
Posts: n/a
#1: Jul 23 '05
I want to publish a patch CD. The CD will contain my files and an HTML page
which will autorun, and tell the user which patch to install. (The Microsoft
MSI installer v2 is comes in two different versions for 98/me and nt4/2000,
and need to install that before my patches get installed. I need to give the
users the correct MSI, so I need to know what their OS is. Most of our users
are not computer people, and have trouble clicking the mouse at the right
time, so they are not likely to be able to determine their OS. I used the
code below to determine if the user is on XP, and it seems to work. The
first line prints "4.0 (compatible; MSIE 6.0; Windows NT 5.1), and I just
test to look for the OS string. One would think there is a better way but I
have zero skill with Javascript.

(this works by itself, but not with other tests for NT 5.0, etc)
if (navigator.userAgent.indexOf('Windows NT 5.1') >= 0){
document.write("<br>")
document.write("<br>")
document.write("<br>")
document.write ("Windows XP detected");
}
else {
document.write ("XP Pro not detected");
}


I have to rely on javascript because this html page is being loaded from a
CD, not a website. I know how to interpret the numbers (5.0, 5.1, etc) to
find out what the OS is, but when I had "if" statements for each OS version,
they ALL printed "xxxxxxxx detected", so I guess a series of "if" statements
will not work. How could I do a switch or case statement to look at
"navigator.userAgent" output and write the link out for the appropriate MSI?
Is there some way I can parse only the OS version from the string, so I just
get the "Windows NT 5.1" or whatever part of the string? In other words,
everything after the last semicolon (I'll just live with the closing
bracket).

Thanks to everyone,
-Jeff Maestas




Randy Webb
Guest
 
Posts: n/a
#2: Jul 23 '05

re: nested if question


Jeff Maestas wrote:[color=blue]
> I have to rely on javascript because this html page is being loaded from a
> CD, not a website. I know how to interpret the numbers (5.0, 5.1, etc) to
> find out what the OS is, but when I had "if" statements for each OS version,
> they ALL printed "xxxxxxxx detected", so I guess a series of "if" statements
> will not work. How could I do a switch or case statement to look at
> "navigator.userAgent" output and write the link out for the appropriate MSI?
> Is there some way I can parse only the OS version from the string, so I just
> get the "Windows NT 5.1" or whatever part of the string? In other words,
> everything after the last semicolon (I'll just live with the closing
> bracket).[/color]

"everything after the last semicolon" won't get you what you need. This
is what IE tells me on Windows ME:

appVersion = 4.0
(compatible; MSIE 6.0; Windows 98; Win 9x 4.90; .NET CLR 1.1.4322)
userAgent = Mozilla/4.0
(compatible; MSIE 6.0; Windows 98; Win 9x 4.90; .NET CLR 1.1.4322)

As you can see, everything after the last semicolon is useless for OS
determination.

But if your users can't determine there own OS, how are they going to
manage to make it through an installation process? Not being obtuse, but
knowing the OS is pretty simple. Start>Settings>Control Panel, System
Icon and most Windows will give it to your there in plain text.

But once you figure out the substring parts that you need, look into the
switch/case to do what you are wanting, instead of nested ifs.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
kaeli
Guest
 
Posts: n/a
#3: Jul 23 '05

re: nested if question


In article <UpKdndBpV69gpFrdRVn2ig@giganews.com>, jeffm@chepnt.net
enlightened us with...[color=blue]
> I want to publish a patch CD. The CD will contain my files and an HTML page
> which will autorun, and tell the user which patch to install. (The Microsoft
> MSI installer v2 is comes in two different versions for 98/me and nt4/2000,
> and need to install that before my patches get installed. I need to give the
> users the correct MSI, so I need to know what their OS is.[/color]

Then use an HTA for windows / IE users and get the value out of the
registry.

http://content.techweb.com/winmag/fixes/2000/0901.htm

See the section marked "registry antics".

--
--
~kaeli~
All I ask is the chance to prove that money cannot make me
happy.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Closed Thread