Reputation: 33
<script>
$(document).ready(function(){
// Checks to see if div has been closed
if(sessionStorage.getItem("hide") != true) {
$('#domainReco').show();
} else {
$('#domainReco').css("display", "none");
}
$("#boxclose").click(function(){
$("#domainReco").fadeOut();
sessionStorage.setItem("hide", true);
return false;
});
});
</script>
echo '<div id="domainReco">';
echo '<a class="boxclose" id="boxclose"></a>';
echo '<h2>You are in the EU store</h2>';
echo '<p>Want to visit the <a href="">US store</a> instead?<p>';
echo '</div>';
When clicking the link, the div does hide but after navigationg to another page, the div is there again. I have searched, but can't seem to fix it.
Thanks in advance
Upvotes: 0
Views: 130
Reputation: 82231
You are making wrong comparison. Variables are not saved as bool, they are saved as string. it should be:
sessionStorage.getItem("hide") !="true"//not (sessionStorage.getItem("hide") !=true)
Upvotes: 3