dcsimg
Browser detect problem
4 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   john_jones
Posted On:   Monday, October 21, 2002 04:37 PM

Hello I have a piece of JavaScript code here : function getlanguage(){ language=navigator.language; if(language) {language=language.substring(0,2);} else {language="z";} switch(language) { case 'en' : window.location = 'http://www.cintech.kiev.ua/index_e_temp.php';break; case 'de' : window.location = 'http://www.cintech.kiev.ua/index_e_temp.php';break; default : window.location = 'http://www.cintech.kiev.ua/index_temp.php';break; } } ]]>]]> The site, I am concerned about has a Russian language home page, but I wish to redirect visitors who are viewing the site from an English language browser (Netscape or Explorer) to an English version of the Russian site. The two pages above, that is,    More>>

Hello

I have a piece of JavaScript code here :



The site, I am concerned about has a Russian language home page, but I wish to redirect visitors who are viewing the site from an English language browser (Netscape or Explorer) to an English version of the Russian site.

The two pages above, that is,

http://www.cintech.kiev.ua/index_temp.php and
http://www.cintech.kiev.ua/index_e_temp.php

are test pages, but represent the Russian home page and the English version respectively.

The problem is that the redirection doesn't work (at least, not for me: I have visited the Russian version through IE6).

Does anybody know why this script isn't working?

A Russian colleague of mine suggests that the script isn't working "because the function getlanguage() isn't called in
the Web page". He also suggests that the script should make use of a variable which can identify the browser's language.

Incidentally, what does the following do:

language=navigator.language;

Any help would be most appreciated.

Best wishes

John

   <<Less

Re: Browser detect problem

Posted By:   Firat_Tiryaki  
Posted On:   Wednesday, October 23, 2002 06:06 AM

you can use document.defaultCharset as well...

Re: Browser detect problem

Posted By:   Firat_Tiryaki  
Posted On:   Wednesday, October 23, 2002 06:00 AM

you can use below properties of navigator object to get the language


navigator.systemLanguage


navigator.userLanguage

Re: Browser detect problem

Posted By:   Firat_Tiryaki  
Posted On:   Wednesday, October 23, 2002 05:58 AM

use if(document.layers) --> for netscape


use if(document.all) --> for IE.

Re: Browser detect problem

Posted By:   Brian_Glodde  
Posted On:   Monday, October 21, 2002 08:54 PM

Here is an example script that properly detects the users language attribute.




navigator.language attribute stores the international standard code for languages. For Netscape, use navigator.language For IEv4, it's navigator.browserLanguage or navigator.userLanguage. This may not be the same as the values specified in the ISO 3166 standard but it should conform to the ISO 639 standard, which allocates two and three letter codes to countries.

Hope that helps!
About | Sitemap | Contact