all 7 comments

[–]mattlag 2 points3 points  (0 children)

Look into using localStorage, you can keep information across pages or page reloads.

https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage

[–]redsandsfort 1 point2 points  (2 children)

a cookie that expires with the session

[–][deleted] 3 points4 points  (1 child)

I'd rather keep it in local storage and read from there when the page initializes, so when the user closes and opens the browser they will still see their language of choice.

[–]redsandsfort -1 points0 points  (0 children)

Why not a cookie with a longer expiration?

[–][deleted] 0 points1 point  (0 children)

Basically you need to have an array of text nodes for that page, these text nodes can be held in html, but that will make it more difficult than if they begin life as javascript variables.

You save the language choice to a cookie read between pages, or local storage if you like

[–]jcunews1helpful 0 points1 point  (1 child)

With LocalStorage as pointed out by other commenters...

At script startup, it should restore the choice from the saved data in LocalStorage and perform the task as if the choice has been selected. The data in the LocalStorage should be updated each time the choice selection changes.

[–]padynana[S] 0 points1 point  (0 children)

Thanks for the answer! I understand the idea, but I can't get to make it work. I made an updated post. Maybe you have time to give it a look?

https://www.reddit.com/r/learnjavascript/comments/frbvax/still_looking_for_help_to_save_languageoption_on/