I am creating an error page that works in 2 languages. The idea is that by default show a <div="404-spanish">
with a URL of the type: www.jonathancenteno.com/estapaginanoexiste . However, when the URL appears / in /, the idea would be that the <div="404-spanish">
would stop showing and show the <div="404-english">
in a URL of the type: www.jonathancenteno.com/en/estapaginanoexiste .
Thanks in advance.
EDITED:
I have tried the following codes and none of them work for me. Although I do not know if they are correct either:
HTML:
<div id="404-page"></div>
<div id="404-spanish"></div>
<div id="404-english"></div>
SCRIPT
Option 1:
<script>
var win = window.location;
var webPath = win.pathname;
var parent = document.getElementById("404-page");
var child = document.getElementById("404-spanish");
var y = document.getElementById("404-english");
//Dividimos la string en un array
var splittedPath = webPath.split("/");
//El primer valor del array segun la estructura mostrada sería el del idioma
switch(splittedPath[0]) {
case "en":
parent.replaceChild(y, child);
break;
default:
break;
}
</script>
Option 2:
<script>
var win = window.location;
var webPath = win.pathname;
var x = document.getElementById("404-spanish");
var y = document.getElementById("404-english");
//Dividimos la string en un array
var splittedPath = webPath.split("/");
//El primer valor del array segun la estructura mostrada sería el del idioma
switch(splittedPath[0]) {
case "en":
x.style.display = "none";
y.style.display = "block";
break;
default:
y.style.display = "none";
break;
}
</script>