2021年4月25日星期日

How would I made this work across all pages that I have it linked to? [duplicate]

I don't really understand how to apply this method to my code, but I'm trying to have dark-mode persist through pages I toggle it on, until I toggle it again on another page.

function myFunction() {     var element = document.body;     element.classList.toggle("dark-mode");  }  

This is my current code to get the page to be dark.

And this is how I'm linking it on each page: <script src="javascript/dark-mode.js"></script>

I have a button on each page, that toggles the dark mode, but when someone navigates to another page, the dark-mode is no longer active I want it to stay on, until its toggled again.

Here's my button code just to show how I set it up: <button id="toggle" title="Toggle Dark Mode" onclick="myFunction()">Lights On/Off</button>

Please describe to me how I would accomplish this, and treat me as if I never done this before...because I haven't.

Thanks!

https://stackoverflow.com/questions/67259587/how-would-i-made-this-work-across-all-pages-that-i-have-it-linked-to April 26, 2021 at 08:46AM

没有评论:

发表评论