I made a dark mode function that changes the background color and text color of my application. It works well, but the thing is when I go to other pages on value="dark", the value attribute is reset, a new page is in value="light". I have to send a dark mode value to other pages.
I googled my question and found out I can't use $ajax(because url is fixed). I know how to make URL parameter like url/foo?bar=value and $_GET['bar'] equals value, but I have no idea where to put this kind of code.
// This is in the <head> of base.blae.php
<button id="dm" style="margin: 19px;" class="btn btn-dark" name="mode" value="light" onclick="
Darkmode(this);
">Darkmode</button>
// JS file
function Darkmode(self){
if($('#dm').val() === 'light'){
Color.backgroundColor('DarkSlateGray');
Color.textColor('white');
$('#dm').val('dark');
} else {
Color.backgroundColor('white');
Color.textColor('black');
$('#dm').val('light');
}
}
I want to use php URL parameter. For example make url like this http://localhost:8000/events?mode=dark and get the value $_get['mode'].
I understand that JS is client-side and PHP is server-side. But I think there's a way to make this work.
Could you explain it with code and where should I put it? Thank you, guys!