Detect language and Redirect BUT stop redirecting if user Manually select a language

Hello @Everyone,

I have 2 pages, the homepage (site.com) and the translated page (site.com/fr).

I’ve put this following javascript on the homepage (in the Custom Code of this page only):

 var userLang = navigator.language || navigator.userLanguage;
 if(userLang != "fr" || userLang != "fr-FR"){
   window.location.replace("/fr");
 }

If the user is French, he’ll be redirected to site.com/fr.

But let’s say this user clicks on a language dropdown somewhere on the site, that lets him choose English or French, and clicks on English, because he wants to see the original english version of the site.

The issue is, the script on the English page will run again, and will redirect him back to the site.com/fr page.
And he’ll never be able to see the site.com original english version.

So the question is, how do I tell the browser “Okay this user finally wants to go to the original site.com, stop running the script” ?

As we can’t use Cookies on Webflow, then I’d guess I need something to tell the script to run just once (but again, how would the script know as the user switched page and came back?)

Or maybe there is a trick I can put on the dropdown English / French links in Custom Attribute?

Any help very much appreciated!

You can almost do everything with custom code.

Great. So now what would be the said custom code (with this js-cookie script) ?

I’m not fluent in JS yet…

This topic was automatically closed after 60 days. New replies are no longer allowed.