Results 1 to 2 of 2

Thread: Retain function action all through website

  1. #1
    Join Date
    Dec 2014
    Location
    NJ
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Post Retain function action all through website

    Trying to retain the action of the function below in all the pages.
    Example: If the user closes the alert box, let it "alert box" stay closed on
    all pages except if the user closes the browser and comes back. I tried local storage but that didn't work out well. How can this be
    achieved?

    My code is as below

    HTML Code:
    $(document).ready(function() {
      if($(".happening").length > 1 ) { 
                 $(".happening-switch").click(function () {
    				 $(".happening:visible").hide().next().show();  
    
    });
       }});
    
    
    $(document).ready(function() {
       if($(".happening").length < 2 ) { 
                 $(".happening-switch").click(function () {
    				 $(".happening:visible").slideUp();          
      });
    
    
    
       }});

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There's no perfect way to do this without a login and database for each user. Failing that (which I admit is probably overkill in this sort of situation), reasonable success can be achieved using a session cookie set and read via javascript.

    I see nothing in the code in your post that references local storage. It would probably be easier to adapt to a javascript session cookie if I could see that, or at least see the rest of the page. Since you're already using jQuery though, there is a good jQuery cookie unit I feel good about recommending:

    http://plugins.jquery.com/cookie/

    Set it with no expiration and it will expire at the end of the browser session. The only drawback with a cookie of this nature is that without javascript, or if the user has cookies turned off, or deletes them before you intended them to expire - all things that usually never happen - but if they do (and they will happen sometimes), the user experience will be a little different then you intend if the cookie is set and kept as programmed. Generally this is no big deal in the rare cases when it does occur. If you want more help, please post a link the page on your site that shows the problematic code.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Sleek Geek (12-17-2014)

Similar Threads

  1. Internal website search function script required
    By stevechand in forum Looking for such a script or service
    Replies: 2
    Last Post: 02-22-2011, 01:00 AM
  2. jquery/jscript website search function
    By neilkw in forum JavaScript
    Replies: 0
    Last Post: 10-26-2010, 10:37 AM
  3. Replies: 15
    Last Post: 10-28-2007, 12:07 AM
  4. Top Navigational Bar III - retain center in FF
    By diski59 in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 04-13-2007, 03:35 PM
  5. retain both IE6 and 7?
    By jass in forum Other
    Replies: 5
    Last Post: 01-07-2007, 09:24 AM

Bookmarks

Posting Permissions

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