Situation:
When an id element selected, get the current URl and change the /en/ part to other language
current URL
http://127.0.0.1:5500/2023/en/activities_summary.html
I want to change it to
http://127.0.0.1:5500/2023/tc/activities_summary.html
code:
$('#tc').on('click',function(){
if(location.href.match(//(?:en|sc)//)){
location.replace(/^.+?/(?:en|sc)//,'tc')
}
})
2
Answers
You can change the /en/ part this way:
(?<=/d{4}/)
– your year part (4 digits)[a-z]{2}
– your language part (2 chars)(?=/)
– closing slash part