2
   

Javascript language detection :: language based redirection

 
 
Reply Wed 30 Jul, 2003 01:56 am
This javascript is used to detect a visitor's language in his/her browser and redirect to the page of your choice. It also has a default page.

Language abbreviations for browsers

Here is the script:

Code:<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;
if (language.indexOf('en') > -1) document.location.href = 'english.html';
else if (language.indexOf('de') > -1) document.location.href = 'german.html';
else if (language.indexOf('it') > -1) document.location.href = 'italian.html';
else
document.location.href = 'defaultpage.html';
// End -->
</script>
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 2 • Views: 40,407 • Replies: 10
No top replies

 
Craven de Kere
 
  2  
Reply Wed 30 Jul, 2003 02:01 am
If you have any questions, need help or want a PHP language redirection script let me know.
niponwar
 
  1  
Reply Mon 20 Jul, 2009 10:05 am
@Craven de Kere,
How i have to do, if want to put the detection for all browsers?

Do i have to copy paste all the script and each time change the name of the browser or i have to specify all the browsers on the general script?

Thank you, waiting the answer.
Robert Gentel
 
  2  
Reply Mon 20 Jul, 2009 12:38 pm
@niponwar,
I'm not sure what you are asking.

If the script doesn't work across browsers that may be due to different JavaScript implementations, and it may not be possible to read local language settings with JavaScript in some browsers.
niponwar
 
  1  
Reply Tue 21 Jul, 2009 07:17 am
@Robert Gentel,
So you want to say, that this script, as it is, should work for every browser?

Because the place that it says "Netscape" i thought i need to change that by, example, FF or IE.
Robert Gentel
 
  2  
Reply Tue 21 Jul, 2009 09:46 am
@niponwar,
It probably doesn't work in every browser. But that Netscape code doesn't mean it only works for Netscape. Give it a try and see if it works.
niponwar
 
  1  
Reply Tue 21 Jul, 2009 02:46 pm
@Robert Gentel,
I got it, thanks dude, this will be a good solution then, cause the company i work for don't want to use PHP, they use ASP, and this sucks, the problem is that i'm good programming in Asp.net, i can read, but not code.
0 Replies
 
HTMLconfused
 
  1  
Reply Fri 4 Jun, 2010 06:30 am
I have no programing expirience and have use MS Front page to creat a web site for our small company. We do business in English and French so I have two different web sites. We have a home page that has an English or French selector butone, but over 50% of customers bounce out of that page. I would like to eliminate it. Do I just copy this code into the HTML of that first page and change the It for Fr. How does the code tell the incoming browser which page to go to? Do you not need to add an adress like, HTTP//www.sumthing//forexample?

Thanks
Marc
Robert Gentel
 
  2  
Reply Sat 5 Jun, 2010 10:24 am
@HTMLconfused,
Marc,

Welcome to a2k.

The part that tells the browser where to go are where it does this:

Code:document.location.href = 'italian.html'


It's using relative paths within the folder, so that above would direct the browser to the "italian.html" file in the same folder.

Replace what's in the quotes with a URL and it will redirect to that URL.
0 Replies
 
tomystein
 
  1  
Reply Mon 6 Feb, 2012 03:05 am
@Craven de Kere,
Hi,
Can you contact me about your script?
Thanks a lot!
0 Replies
 
rozer20
 
  1  
Reply Sun 25 Mar, 2012 05:57 am
Thanks for the java script.
0 Replies
 
 

Related Topics

 
  1. Forums
  2. » Javascript language detection :: language based redirection
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.07 seconds on 11/21/2024 at 09:24:49