Reputation: 1
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("HTML6");
var xbutton = document.getElementById("hide-header");
if(pagehead.style.display == "none") {
pagehead.style.display = "block";
xbutton.innerHTML = "<img border='0' src='https://lh5.googleusercontent.com/-S5r38GtSF6s/Ui04r4eS0yI/AAAAAAAADpQ/qRnrSX2MpcY/w16-h15-no/close+X.png'/>";
}
else {
pagehead.style.display = "none";
xbutton.innerHTML = "<img border='0' src='https://lh5.googleusercontent.com/-S5r38GtSF6s/Ui04r4eS0yI/AAAAAAAADpQ/qRnrSX2MpcY/w16-h15-no/close+X.png'/>";
}
}
</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
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
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
Reputation: 34895
You need to use the browser cookies. Take a look at jQuery.cookie. There are examples there.
Upvotes: 1