I'm attempting to create a bilingual webpage in Spanish and English. My goal is to have a main page where the user selects the language, and once chosen, the page remembers the language preference for future visits instead of prompting the choice again.
What would be the most effective way to achieve this?
EDIT-- I followed advice to use localStorage, but as someone unfamiliar with JavaScript, I've hit a roadblock. While I can input 'es' or 'en' into the 'locale', I am unable to redirect at all. Here is the code snippet:
<script>
(function (){
'use strict';
var eng = document.querySelector('.eng')
function setLocalStorage(){
eng.addEventListener('click', () => {
localStorage.setItem('locale','en')
})
}
setLocalStorage()
}());
(function (){
'use strict';
var esp = document.querySelector('.esp')
function setLocalStorage(){
esp.addEventListener('click', () => {
localStorage.setItem('locale','es')
})
}
setLocalStorage()
}());
if (localStorage.getItem('en') === 'en') { window.location='eng.html'; }
if (localStorage.getItem('es') === 'es') { window.location='esp.html'; }
</script>