DEV Community

Discussion on: CSS-only dark mode

Collapse
 
legebeker profile image
LB

I read your post, but the javascript used to save the setting does not work in sub-folders in Firefox. Is there any way to have it work?

Collapse
 
kleinfreund profile image
Philipp Rudloff

Hello. I’m not quite sure I follow. What do you mean with “sub-folders in Firefox”? The bit of JavaScript saves the setting in your browser.

Collapse
 
legebeker profile image
LB

In Firefox, the JavaScript works perfectly with the top-level pages, like /index.html and /projects.html. The pages in sub-directories, for example /news/index.html and /about/team.html, get a separate setting, so when I change it to darkmode on /index.html, it gets changed on all top-level pages, but not on the sub-level(/news/index.html). It gets saved, but only separate. Is there any way to get it to work on Firefox? It would help a lot.

Thread Thread
 
kleinfreund profile image
Philipp Rudloff

localStorage (and sessionStorage) store their data on a per-domain basis. For example, on my website, my localStorage items are available as long as I’m on “kleinfreund.de”. However, if I were to navigate to “www.kleinfreund.de”, I would no longer have access to the items from “kleinfreund.de” and the other way round.

In your case, it should work as long as the underlying domain is the same.

Some background: From a browser’s point of view, “kleinfreund.de” and “www.kleinfreund.de” could be entirely different websites, served by completely separate web server. That’s one of the reasons why this distinction is made.