It seems to me that your code should work like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script>
window.onload = function () {
var ln = navigator.language || navigator.userLanguage;
if (ln == 'en') {
console.log("english")
window.location.replace("indexEN.html");
} else if (ln == 'es-419') {
console.log("español")
window.location.replace("indexES.html");
}else if (ln == 'de-DE'){
console.log("alemán")
window.location.replace("indexDE.html");
}else{
console.log("desconocido")
}
}
</script>
</body>
</html>
OBSERVATIONS
To obtain the browser language it would be: var ln = navigator.language || navigator.userLanguage;
For the case of the English language if it is en
In the case of Spanish, the label should be: es-419
For the case of the German language it should be: de-DE
When using window.onload
this code will start working as soon as the page loads, so I think it should only go in one that redigija to any other
What happens is that for each language there are variants
In addition to the above you should use window.location.replace
which replaces the current resource with one passed as parameter
window.location.replace("https://www.es.stackoverflow.com");
Try using it because it does not keep the pages in history