I added dark mode to a website, and added a .js to save the setting the person choose. It works perfectly in all the pages on the same level as index, but every page with its own folder, does not get the saved setting in firefox. It works perfectly in Chrome. Here the javascript that I used:
document.addEventListener('DOMContentLoaded', function () {
const checkbox = document.querySelector('.dark-mode-checkbox');
checkbox.checked = localStorage.getItem('darkMode') === 'true';
checkbox.addEventListener('change', function (event) {
localStorage.setItem('darkMode', event.currentTarget.checked);
});
});
In the pages in the folders I used <script src="../js/darkmode.js"></script>
. How to have the setting they choose work on the whole page?