Use localStorage
to save information in the browser and then use it:
Example in 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 the information "1" (can be any information, the important thing is that the localStorage
has some value, even a true -- localStorage.mostrabotao2 = true;
) in the localStorage
and checks if it has value every time the page is loaded. If there is value, the button displays, if not, does nothing and the button remains hidden by CSS.
Put it all inside a div, give it a
id
it and use Document.getElementById(id_da_div).innerHTML. Use theinnerHTML
– isaque