Jump to content

[Code Injection] Language Switch Button doesn't work on mobile

Recommended Posts

Hello Squarespace community,

I hope you're all doing well! I am seeking some assistance with a coding injection issue I am facing on the mobile version of my website. Specifically, I am having trouble getting the code for my language change button to work properly.

On the desktop version of my site, the language change button functions perfectly fine. However, when it comes to the mobile version, it doesn't seem to respond or trigger the expected behavior. I have tried several approaches, but none have yielded the desired result.

I would greatly appreciate it if someone could guide me on how to correctly implement the code for the language change button on the mobile version of my Squarespace website. I am using the Squarespace platform for my website, and any advice or suggestions would be extremely helpful.

Here's the code I currently have for the language change button :

<script>
var container = document.createElement("div");
container.classList = "header-actions-action header-actions-action--cta preFade fadeIn"
container.setAttribute("data-animation-role", "header-element")
container.setAttribute("style", "transition-timing-function: ease; transition-duration: 0.4s; transition-delay: 0.02")

var link = document.createElement("a");
link.classList = "btn btn--border theme-btn--primary-inverse sqs-button-element--primary";
link.setAttribute("id", "monBouton");
link.setAttribute("style", "color: black; background-color: white; border: 2px solid black; padding: 20px 37.41px; text-decoration: none; cursor: pointer;");
  
<!-- replace "YOUR_URL_LINK_HERE" -->
link.setAttribute("href", "https://www.en.simonsonlandscape.com/")
link.setAttribute("target", "_self")
  
link.onmouseover = function() {
    this.style.backgroundColor = 'black';
    this.style.color = 'white';
}

link.onmouseout = function() {
    this.style.backgroundColor = 'white';
    this.style.color = 'black';
}

<!-- replace "ENGLISH" -->
var linkText = document.createTextNode("ENGLISH");
link.appendChild(linkText);
container.appendChild(link);

var neighbour = document.querySelector(".header-display-desktop .header-actions--right div:last-child");
var neighbourParent = document.querySelector(".header-display-desktop .header-actions--right")
neighbourParent.insertBefore(container, neighbour);
</script>

Thank you all in advance for your time and assistance. I'm looking forward to your valuable insights and suggestions !

Link to comment
  • Replies 4
  • Views 430
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

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.