homepage Welcome to WebmasterWorld Guest from 54.166.96.101
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
user language - browser recognition and redirect javascript
bignooz

10+ Year Member



 
Msg#: 318 posted 7:42 pm on Mar 20, 2003 (gmt 0)

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>

 

DrDoc

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



 
Msg#: 318 posted 10:31 pm on Mar 20, 2003 (gmt 0)

Try this:

document.write(navigator.userLanguage)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved