Javier Ocampo
Javier Ocampo

Reputation: 1

How to make the browser remember what the user choose?

I have this code. I don't really know anything about Javascript so I pretty much found it on the internet. What it does basically is closes the big header image at the top of the page. I want to know how do I make it so that the browser remembers what the user has chosen? FOr example if the person clicks to hide it and then you reload the page, it should remain hidden and not default to the original.

<script language='javascript'>
function toggle() {
var pagehead = document.getElementById(&quot;HTML6&quot;);
var xbutton = document.getElementById(&quot;hide-header&quot;);
if(pagehead.style.display == &quot;none&quot;) {
pagehead.style.display = &quot;block&quot;;
xbutton.innerHTML = &quot;<img border='0' src='https://lh5.googleusercontent.com/-S5r38GtSF6s/Ui04r4eS0yI/AAAAAAAADpQ/qRnrSX2MpcY/w16-h15-no/close+X.png'/>&quot;;
}
else {
pagehead.style.display = &quot;none&quot;;
xbutton.innerHTML = &quot;<img border='0' src='https://lh5.googleusercontent.com/-S5r38GtSF6s/Ui04r4eS0yI/AAAAAAAADpQ/qRnrSX2MpcY/w16-h15-no/close+X.png'/>&quot;;
}
} 
</script>

Not sure if it's even possible. I have no idea really. Here is my website for reference: linkvier.com I really hope I can get this code to work since I plan on using it on ads and stuff as well.

Upvotes: 0

Views: 78

Answers (3)

Theseas Maroulis
Theseas Maroulis

Reputation: 66

If you don't have to support old browsers then check out html's 5 localStorage it's pretty awesome. :-)

For older browsers use cookies or one of those scripts that emulate localStorage using cookies.

Upvotes: 0

internals-in
internals-in

Reputation: 5038

as far as i know http is stateless you can use cookies to get this Read Stateless_protocol

look at checkCookie() getCookie(c_name) and setCookie(c_name,value,exdays) here @
w3schools Cookie Examples

Upvotes: 0

Konstantin Dinev
Konstantin Dinev

Reputation: 34895

You need to use the browser cookies. Take a look at jQuery.cookie. There are examples there.

Upvotes: 1

Related Questions