Forum Moderators: open

Message Too Old, No Replies

OS indentification script wount work..

         

carramba

12:16 pm on Aug 13, 2003 (gmt 0)

10+ Year Member



script:

<script language="JavaScript" type="text/javascript">
var text_win="Welcome Windows-Freak"
var text_mac="Welcome Macintosh-Freak"
var text_linux="Welcome Linux-Freak"
var text_unix="Welcome Unix-Freak"
var text_unknown="Welcome"
var text=""
var ua = 'ShonenScape'.toLowerCase();
if (ua.indexOf("win")!= -1) {text=text_win;}
else if (ua.indexOf("mac")!= -1) {text=text_mac;}
else if (ua.indexOf("linux")!= -1) {text=text_linux;}
else if (ua.indexOf("x11")!= -1) {text=text_unix;}
else {text=text_unknown;}
</script>

************************************************************
calling script:

<script language="JavaScript" type="text/javascript">document.write(text)</script>

************************************************************

problem:
script don't recognaise OS.

I don't se hwy it woun't work.. any ideas?

thanx in advance

drbrain

4:01 pm on Aug 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Because the value of the variable 'ua' is 'shonenscape'. It should be navigator.userAgent.

carramba

5:38 pm on Aug 13, 2003 (gmt 0)

10+ Year Member



but 'ua' is 'ShonenScape' not 'shonenscape' and script still don't work

drbrain

10:11 pm on Aug 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




var ua = 'ShonenScape'.toLowerCase();

Should be var ua = navigator.userAgent.toLowerCase(). In your code, after the toLowerCase(), ua == 'shonenscape'


if (ua.indexOf("win")!= -1) {text=text_win;}

"win" is not in the string "shonenscape"


else if (ua.indexOf("mac")!= -1) {text=text_mac;}
else if (ua.indexOf("linux")!= -1) {text=text_linux;}
else if (ua.indexOf("x11")!= -1) {text=text_unix;}
else {text=text_unknown;}

Nor in any of the rest of these.

carramba

10:41 am on Aug 17, 2003 (gmt 0)

10+ Year Member



u are right.. I cudn't get it work with ShonenScape so I shanget to navigator.userAgent now it works perfect!