Hi, I am doing a website on Webflow, but need to implement a special off-site translation service, and need some help on javascript.
I need to make a language switch and make it able to go to the respective translated page. The link of that switch is given an id “ext-trans”:
<a id="ext-trans" href="#" > LINK </a>
Is there a way to detect the current browser’s URL, such as:
https://cuhkintouch-cpr.webflow.io/xxxxx
https://cuhkintouch-cpr.webflow.io/en/xxxxx
https://cuhkintouch-cpr.webflow.io/tc/xxxxx
https://cuhkintouch-cpr.webflow.io/sc/xxxxx
and then use a javascript to replace href=“#” with this pattern:
https://translate.itsc.cuhk.edu.hk/uniTS/cuhkintouch-cpr.webflow.io/tc/xxxxx
( no matter the current URL is /en/ or /tc/ or /sc/, just need /tc/ in result )
( xxxxx is the remaining path )
I tried to write a javascript to handle this, but it looks like something’s wrong and it does not work…
<script>
$('#ext-trans').attr('href', 'https://translate.itsc.cuhk.edu.hk/uniTS/' + window.location.hostname + '/tc' + window.location.pathname.substr(3))
</script>
It would be so great if anyone would know how to do it.
Thanks a lot in advance!
Anthony
( The Website | Read-only link )