I\’ve a simple show and hide div.
The div automatically loads on loading the page and then you can close the div by clicking close.
Once you refresh the page the div shows up again, how do I code it to once closed, to not open again for say a month.
Thanks in advance.
Ben
This is the code I have so far;
<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js\" type=\"text/javascript\"></script>
<script src=\"http://innosite.s3.amazonaws.com/cookie/jquery.cookie.js\"></script>
<script type=\"text/javascript\">
$(document).ready(function() {
// hides the slickbox as soon as the DOM is ready
$(\'#slickbox\').show();
// shows the slickbox on clicking the noted link
$(\'#slick-show\').click(function() {
$(\'#slickbox\').show(\'slow\');
return false;
});
// hides the slickbox on clicking the noted link
$(\'#slick-hide\').click(function() {
$(\'#slickbox\').hide(\'fast\');
return false;
});
// toggles the slickbox on clicking the noted link
$(\'#slick-toggle\').click(function() {
$(\'#slickbox\').toggle(400);
return false;
});
});
</script>
<script type=\"text/javascript\">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = \"; expires=\"+date.toGMTString();
}
else var expires = \"\";
document.cookie = name+\"=\"+value+expires+\"; path=/\";
}
function readCookie(name) {
var nameEQ = name + \"=\";
var ca = document.cookie.split(\';\');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==\' \') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
//user closes your box
createCookie(\'mybox\',1,30);
//check if the box should be hidden
if (readCookie(\'mybox\'))
$(\'#slickbox\').hide();
</script>





Rating:
The post javascript – How to keep div hidden after page refresh? appeared first on Javascript ASK.
via Javascript ASK http://javascriptask.phpfogapp.com/javascript-how-to-keep-div-hidden-after-page-refresh.html
No comments:
Post a Comment