I’m a beginner in JavaScript and have the following problem, I have multiple pages in 2 languages. Later maybe more. I use a javascript var to set the language. Either:
Var language=”de”; or var language=”en”;
then I used this to load the correct language file:
<script src="javascript"+language+".js" type="text/javascript"></script>
Is there a way to change this variable with an onclick() event. So that it changes and stays changed until I change it again?
Thanks for you time.
You can add scripts dynamically like this:
This code binds clicks on a number of
<a>
elements, each with a language data attribute. Clicking on one creates a new<script>
with the correct language and adds it to the page. It also deletes any scripts that you've added previously this way, to ensure no clashes.