...

View Full Version : detecting the OS AND forwarding to another page



cuz
04-12-2003, 11:00 PM
Hello, All. I have to create a JS that not only detects a computer's OS, (in this case, just Mac) but also forwards the user to another page based on the results of the detection. I've found tons of ways to detect the OS, but none that can forward the user to a certain page afterwords. Can anyone help me out?

Thanx in advance...

x_goose_x
04-12-2003, 11:07 PM
<script language="JavaScript1.2" type="text/javascript">
if (navigator.userAgent.indexOf("Win")) {
location.replace("windows.html");
} else if (navigator.userAgent.indexOf("Mac")) {
location.replace("macintosh.html");
} else {
location.replace("other.html");
}
</script>

cuz
04-13-2003, 12:53 AM
It worked like a charm goose!!!! THANX!!!!!

cuz
04-13-2003, 01:33 AM
Actually, I spoke too soon...

The code is working for Windows bit not for Maca,

Here's my code:

<script language="JavaScript1.2" type="text/javascript">
if (navigator.userAgent.indexOf("Win")) {
location.replace("http://www.eh21.com/shop/");
} else if (navigator.userAgent.indexOf("Mac")) {
location.replace("http://www.eh21.com/shophtml/");
} else {
location.replace("http://www.eh21.com/shophtml/");
}
</script>

x_goose_x
04-13-2003, 05:42 AM
Sorry I don't have a mac I can test it on. Try doing alert(navigator.userAgent); then see the output. The indexOf function is case sensitive, maybe thats the problem.

brothercake
04-13-2003, 01:11 PM
Originally posted by x_goose_x
The indexOf function is case sensitive, maybe thats the problem.
Yes it is; you need to check it in lower case:

var agt = navigator.userAgent.toLowerCase();

if(agt.indexOf("mac")!=-1) {

cuz
04-13-2003, 03:58 PM
Hey guys. First and foremost, thanx for all your help!!!!!!! :)

I pasted the following code in my page. Unfortunatly I still can't get it to work for Macs:



<script language="JavaScript1.2" type="text/javascript">
var agt = navigator.userAgent.toLowerCase();
if(agt.indexOf("mac")!=-1) {
location.replace("macintosh.html");
} else if(agt.indexOf("win")!=-1) {
location.replace("windows.html");
} else {
location.replace("other.html");
}
</script>


Am I doing something way off base here?

Thanx in advance...

cuz
04-13-2003, 08:59 PM
COMPLETLY ignore that last post! It works perfectly...I just did something wrong on my end.

Thanx to goose & brother for their help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum