Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2008
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Show cookie-enabled Jquery notification message on page load

    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 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

    Code:
    <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

  • #2
    New Coder
    Join Date
    Jan 2008
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by treigh View Post
    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 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

    Code:
    <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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •