0
I have a button on an accessibility bar, which when clicked calls the following function:
function contraste2 ()
{
var css = document.querySelector('#css');
var contraste = Cookies.get("contraste");
if (contraste == "contrasteinativo" || contraste =="undefined")
{
Cookies.set("contraste","contrasteativo", { expires: 365 });
css.setAttribute('href', 'estiloscontraste.css');
}
if (contraste == "contrasteativo")
{
css.setAttribute('href', 'estilos.css');
Cookies.set("contraste","contrasteinativo", { expires: 365 });
}
}
The application of contrast css takes place through an alternative css, called in the function.
Only this code is wrong, I know.
If the contrast has not yet been applied (cookie = Undefined), then it activates the contrast and sets the cookie as active.
Only then, it checks if the cookie is active, and if it has it disables the contrast. This way, there is no change in the page (because the cookie will always be inactive).
I’m not able to create a logic for this, I thought of making a kind of counter to check if the button has already been clicked, a counter through another cookie.
Where does this "Cookies.set" "Cookies.get" api come from"
– Jorge Costa
I am thereby including <script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script> I have followed the guidelines here: https://github.com/js-cookie/js-cookie
– Recurso de Acessibilidade