Header Ads Widget

Responsive Advertisement

JavaScript to identify browser language and redirect user to a specific page



Source Code Helpful?

  1. Using that code you can successfully enable to redirect your websites according to browser language 
  2.  Source code is helpful for all browsers (IE, Chrome, Mozilla, Safari, and the App versions etc)
  3. In current example you can test that code with three type of languages like English, French and German

Source Code:


<script>
$(document).ready(function(){
 detectLang();
});
function detectLang(){
 debugger;
 var lng=navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en-US';
 var lang=lng.split('-');
 if(lang[0]=='fr'){
  window.location.href=window.location.protocol+"//example.com/fr/index.php";
 }else if(lang[0]=='de'){
  window.location.href=window.location.protocol+"//example.com/de/index.php";
 }
 else{
   window.location.href=window.location.protocol+"//example.com/en/index.php";
 }
}
</script>

Post a Comment

0 Comments