I was hosting my site on Github Pages and just switched to Netlify and change the DNS settings to point to Netlify (from Namecheap). I deployed it from my git repo (after removing it from pages).
The site is live pwenterprises.netlify.app and deployment worked fine but none of the buttons on my site are working. This wasn’t an issue in my local machine (using vis studio) or previous site on github.
I check the console and getting this error for some reason:
Uncaught TypeError: Cannot read properties of null (reading ‘getElementsByClassName’)
in my script.js:
// Add active class to the current control button (highlight it)
var btnContainer = document.getElementById(“btn-container”);
var btns = btnContainer.getElementsByClassName(“btn”);
for (var i = 0; i < btns.length; i++) {
btns[i].addEventListener(“click”, function () {
var current = document.getElementsByClassName(“active”);
current[0].className = current[0].className.replace(" active", “”);
this.className += " active";
});
}
I know you mentioned it, I’m saying again it’s largely irrelevant.
You can’t debug from that perspective, you can only debug from what you can actually see, the errors that are occurring, by debugging them you may determine some other “root cause”.
None.
While you say you’ve changed nothing, something may have changed.
The easiest way to figure it out, is to debug it.
Note that Netlify is only “hosting the site” it’s not “running the site”.
The browser is running the site, and it’s in the browser that the errors are occuring.
If you really wanted to get pedantic, you could take the files from the result of a build on Github and the result of a build on Netlify and do a diff on the files.
If there is some difference between the output of your build running on the two services, that would reveal it.
^ This has ‘fixed it’ but only because it’s “turned off” the code that’s broken
if (href.endsWith(".html") || href.startsWith("http")) {
window.location.href = href;
}
^ This is the cause for your links not working
As I’d screenshot, that menu logic hijacks the behavior of links and then only navigates to them when they either end with .html or start with http.
That won’t be playing nice with Netlify’s “Pretty URL’s” feature:
Netlify’s Pretty URLs feature, which is enabled by default for sites and standardizes your URLs.
When Pretty URLs are enabled, Netlify forwards paths like /about to /about/ (a common practice in static sites and single-page apps) and rewrites paths like /about.html to /about/.
So your links don’t contain either .html or http, (e.g. /services/import-export), and thus aren’t being handled at all.
You just need to adjust your JavaScript to be more robust.