...

View Full Version : Show cookie-enabled Jquery notification message on page load



treigh
12-18-2010, 12:18 AM
Hi guys, I have the following jquery code that shows a notification box on page load and closes it when the user clicks on the close button.
Once the box has been closed, It shouldn't be displayed again next time the page loads. I understand I need to use cookie to get this done and I've alreaded included the Jquery cookie plugin (http://plugins.jquery.com/files/jquery.cookie.js.txt) in the head, but from there I don't know how to move on. Someone helped out, but we couldn't figure it out. I would appreciate any help I can get


<script src="includes/js/scripts/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
var $box = $(".alertbox"),
stateCookieName = 'alertbox_state',
alreadyClosed = $.cookie(stateCookieName);

// The box should already be hidden initially (using CSS preferrably).
// If not, uncomment the line below:
$box.hide();

// Show the box if it hasn't already been closed.
if (alreadyClosed != 1) {
$box.fadeIn(900);
}

$box.find('.close').click(function() {
$box.fadeOut("slow");
$.cookie(stateCookieName, 1);
});
});
</script>


I'm using Chrome 8/FF 4B7

treigh
12-18-2010, 05:31 AM
Hi guys, I have the following jquery code that shows a notification box on page load and closes it when the user clicks on the close button.
Once the box has been closed, It shouldn't be displayed again next time the page loads. I understand I need to use cookie to get this done and I've alreaded included the Jquery cookie plugin (http://plugins.jquery.com/files/jquery.cookie.js.txt) in the head, but from there I don't know how to move on. Someone helped out, but we couldn't figure it out. I would appreciate any help I can get


<script src="includes/js/scripts/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function() {
var $box = $(".alertbox"),
stateCookieName = 'alertbox_state',
alreadyClosed = $.cookie(stateCookieName);

// The box should already be hidden initially (using CSS preferrably).
// If not, uncomment the line below:
$box.hide();

// Show the box if it hasn't already been closed.
if (alreadyClosed != 1) {
$box.fadeIn(900);
}

$box.find('.close').click(function() {
$box.fadeOut("slow");
$.cookie(stateCookieName, 1);
});
});
</script>


I'm using Chrome 8/FF 4B7


The issue is resolved in all browsers except Chrome 8



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum