I am having a element with a X (close) icon in the top right corner. When clicking that close icon I am hiding the element with some jQuery. When I am on a new page in the same session the element comes back again. I want to set a cookie for hiding the element after the user clicked the close icon in the session. I found this to set a cookie but what needs to be inside?:
This is my code for the element
jQuery(document).ready(function() {
//Add close icon in top right corner of element
jQuery("<a class='verwijderen_messenger' href='#'></a>").insertBefore("a#fbmsg-icon");
jQuery("a.verwijderen_messenger").live("click", function(event) {
event.preventDefault();
//Hide element
jQuery("a#fbmsg-icon").css("display", "none");
jQuery("a.verwijderen_messenger").css("display", "none");
//
sessionStorage.setItem("messenger", "hidden");
});
if (sessionStorage.getItem("messenger") == "hidden") {
jQuery("a.verwijderen_messenger").remove();
jQuery("a#fbmsg-icon").remove();
}
else {}
});
You could use localStorage.setItem(key,value)
to set a variable into the local browser and localStorage.getItem(key)
to get.
In your example it would be: localStorage.setItem(messenger, 'hidden')
and then get the variable in the next window by
if(localStorage.getItem(messenger)=='hidden') {
hideDiv();
} else {
showDiv();
}