0

I have a sidebar menu created with w3school. The issue is that until the page is fully loaded (including images and Adsense advertising), the Menu button does not react to clicks.

The javascript code I use is the basic one, inside head tags:

var openMenu = false;

function w3_open() {
  if (openMenu) {
     document.getElementById("mySidebar").style.display = "none";
     openMenu = false;
   } else {
     document.getElementById("mySidebar").style.display = "block";
     openMenu = true;
   }
  
}

function w3_close() {
   document.getElementById("mySidebar").style.display = "none";
   openMenu = false;
}

<button class="w3-button w3-teal w3-xlarge w3-dark-gray" onclick="w3_open()">☰ Menu</button>

I need the menu to be clickable while the webpage is loading.

Leito
  • 1
  • Are there errors in the browser console? – Pointy May 25 '23 at 01:57
  • The issue would most likely be from how/when you're loading your script. But from the code you have posted we cannot tell. Please post a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – ngearing May 25 '23 at 02:02

1 Answers1

0

For someone who can help you... I found the solution. After messing around with javascript and html code for hours... I found out it was all due to ROCKET LOADER, a Cloudflare service.

You can disable the service or add data-cfasync="false" to the script

Leito
  • 1