Source Code Helpful?
- Using that code you can successfully enable to redirect your websites according to browser language
- Source code is helpful for all browsers (IE, Chrome, Mozilla, Safari, and the App versions etc)
- 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>
0 Comments