Use localStorage
to save information in the browser and then use it:
Example on JSFiddle :
CSS:
button#botao1 {display: none; margin-top: 5px;}
#esconder{ display: none; margin-top: 5px; }
HTML:
<button id="mostrar" onClick="javascript: mostrarBt();">Mostrar Botão</button>
<button id="esconder" onClick="javascript: escondeBt();">Esconder Botão</button>
<button id="botao1">Botão 1</button>
JS:
window.onload = function(){
if(localStorage.mostrabotao2){
mostrarBt();
}
}
function mostrarBt() {
document.getElementById("botao1").style.display="block";
document.getElementById("esconder").style.display="block";
localStorage.mostrabotao2 = 1;
}
function escondeBt() {
document.getElementById("botao1").style.display="none";
document.getElementById("esconder").style.display="none";
localStorage.clear();
}
The above code saves information "1" (it can be any information, the important thing is that localStorage
has some value, even a true - localStorage.mostrabotao2 = true;
) in localStorage
and checks to see if it has value every time the page loads. If there is a value, the button is displayed, otherwise it does nothing and the button is still hidden by CSS.