I am trying to create a Bootstrap alert box that remembers when users click the close button. I guess I need to store that information in a cookie. Ideally that cookie will only last for that current session, and next they return the box will appear again.
I am using the jQuery-Cookie plugin. I uploaded it to /jquery-cookie-master
. Plugin can be found here.
This is what I've got so far by following code found here.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/jquery-cookie-master/jquery.cookie.js"></script>
<script>
function runOnLoad(){
if($.cookie('alert-box') == null) {
$.cookie('alert-box', 'open', { expires: 7 });
} else if($.cookie('alert-box') == 'close') {
$(".close").hide();
}
</script>
HTML:
<body onload="runOnLoad()">
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert" href="hideMe.php" onclick="hideMe()">×</button>
<p>
<strong>FORUM UPGRADE:</strong> In light of our recent surge in popularity we upgraded our forum and unfortunately lost all the old threads in the process.
</p>
<p>
In an effort to kick-start the forum again we need your help. Sign up now and leave a post (it's free). Once we reach 100 threads every member will receive a special gift.
</p>
<p>
<a href="http://example.com/forum/#/entry/register">
<strong>Sign up to the forum now</strong>
</a>.
</p>
</div>
</body>
Unfortunately it's not working.When I click the close button it does not remember that action and if I refresh the page the alert box will appear again.
What have I done wrong?