Welcome to WebmasterWorld Guest from 54.163.115.193

Forum Moderators: open

user language - browser recognition and redirect javascript

   
7:42 pm on Mar 20, 2003 (gmt 0)

10+ Year Member



Hi, to redirect my international traffic to the apropriate target/language I am using a script in a html page wich is not running very well, in fact the script as follow just recognise the original language of the browser (the language in wich the browser was downloaded)
If someone can purpose a better script...
Thanks!
Bignooz

<script language="Javascript1.2">

function recup_lg()
{
var lgr;
if (verif_lg(navigator.userLanguage)) { lgr = verif_lg(navigator.userLanguage); }
else if (verif_lg(navigator.systemLanguage)) { lgr = verif_lg(navigator.systemLanguage); }
else if (verif_lg(navigator.browserLanguage)) { lgr = verif_lg(navigator.browserLanguage); }
else if (verif_lg(navigator.language)) { lgr = verif_lg(navigator.language); }
else { lgr = 'us'; }

return lgr;
}

function verif_lg(lg_tmp)
{
if(lg_tmp)
{
if(lg_tmp.indexOf('fr')!= -1) { return 'fr'; }
else if (lg_tmp.indexOf('en')!= -1) { return 'us'; }
else if (lg_tmp.indexOf('es')!= -1) { return 'es'; }
else if (lg_tmp.indexOf('pt')!= -1) { return 'pt'; }
else if (lg_tmp.indexOf('nl')!= -1) { return 'nl'; }
else if (lg_tmp.indexOf('de')!= -1) { return 'de'; }
else if (lg_tmp.indexOf('it')!= -1) { return 'it'; }
else { return ''; }
}
}

var lg_nav = recup_lg();

var url_redir;

if(lg_nav == 'fr') { url_redir = 'http://website.com'; }
else if (lg_nav == 'us'){ url_redir = 'http://website.com'; }
else if (lg_nav == 'de'){ url_redir = 'http://website.com'; }
else if (lg_nav == 'it'){ url_redir = 'http://website.com'; }
else if (lg_nav == 'pt'){ url_redir = 'http://website.com'; }
else if (lg_nav == 'es'){ url_redir = 'http://website.com'; }
else if (lg_nav == 'nl'){ url_redir = 'http://website.com'; }
else{ url_redir = 'http://website.com'; }

window.location = url_redir;
</script>

10:31 pm on Mar 20, 2003 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Try this:

document.write(navigator.userLanguage)

 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month