Jump to content

Script keeps causing page to reload

Recommended Posts

I am trying to make a site for both German and English readers, but don't have the budget to pay for a translation extension.  So, we are thinking about doing each page in German and English, and based on the user's language preferences set in the browser, direct to the corresponding page. For this logic, I put the following in my Header section of the code injection:

<script>
const userLanguage = window.navigator.language.slice(0, 2);
const requested = window.location.pathname;
  
if(userLanguage !== 'de') {
	location.href = `https://effektiver-altruismus-germany.squarespace.com/en/${requested}`;
} else {
	location.href = `https://effektiver-altruismus-germany.squarespace.com/${requested}`; 
}
</script>

But when I do this, the site glitches and keeps refreshing over and over again while adding 'en' to the url upon every refresh. Does anyone know what's happening?

Link to comment
  • Replies 3
  • Views 982
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

I don't have any specific solutions just some general comments.

For the footer. If you are on v7.1 you make two sections, in the footer, and then you add code to the appropriate section of Brad's code to hide/show the sections based on the language.

For the header. I assume you must mean there are elements in the header that aren't being translated?  I assume the navigation elements are. That is the point of Brad's code. For the header you use the same method of tying into Brad's code to hide/show elements based on language.

Use of Brad's code is common. Some of these particular issues may have been touched on in this forum. I have no specific pointers. Try the forum search function. Try search terms like brad, good, language, switcher, and etc.

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.