Jump to content

Language toggle working on desktop but not mobile

Recommended Posts

Hi there! Having some issues with this code which works perfectly fine on desktop but not mobile and I can't figure out why.

The website is French and English, the language button is meant to bring the user back to the same page they are on but in the other language. This code works fine on desktop but on mobile... it brings the user back to the language button set URL slug. Help!

 

<style>
  /* hide items on desktop */
nav.header-nav-list>.header-nav-item:nth-child(odd) {
    display: none;
}
/* hide items on mobile */
[data-folder="root"]>div:first-child>div:first-child>div:nth-child(odd) {
    display: none !important;
}
</style>
<script>
  window.addEventListener('load', function () {
  document.querySelectorAll(".header-nav-item--external a").forEach(function(t) {t.href = "/fr/our-services"});
});
</script>

Link to comment
  • Replies 3
  • Views 1.3k
  • Created
  • Last Reply

Top Posters In This Topic

Try changing code to this

<style>
  /* hide items on desktop */
nav.header-nav-list>.header-nav-item:nth-child(odd) {
    display: none;
}
/* hide items on mobile */
[data-folder="root"]>div:first-child>div:first-child>div:nth-child(odd) {
    display: none !important;
}
</style>
<script>
  window.addEventListener('load', function () {
  document.querySelectorAll('div[class*="-nav-item"] a').forEach(function(t) {t.href = "/fr/our-services"});
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

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.