I have a very simple offline html page looking like this:
HEADER
Body Text
But the contents of the header and body text need to changed based on input param in url (I think it should be looking like this: "index.html?lang=abc"?), the text strings for on each lang are pre-defined and if possible both the javaScript code and the possible values of text fields should be stored inside the html page itself.
I have basically zero knowledge about html and JavaScript while needing it asap so I’ll be very glad if you anyone can help me with this with a simple solution so I can get it with my tofu brain. Thank you.
I tried to follow some examples and adapted some code samples on SO and google, and at least got the split lang parameter right, but while trying to change the text field it bricked my html and it can’t be displayed. I cannot access Youtube during work hour to search for solutions there.
3
Answers
You didn’t specify what you want to do, so my example will be very basic.
This example uses body onload to trigger the JavaScript function parsePageUrl which reads window.location.href into a new URL. Then the entire URL is written into the div object with the id that equals divUrl, and only the search part of the URL into another div object.
Maybe You can use JavaScript to parse the URL parameters and update the text content of your HTML elements accordingly. Try it out!
Does your desire is to make a translation based on the lang param in URL?
I assume that your text element has a id = ‘text’
<p id="text">hello</p>