Welcome Guest, Not a member yet? Register   Sign In
jQuery Cookie Plugin - won't save my cookie!
#1

[eluser]IamPrototype[/eluser]
Hey boys and girls. On my website I'd like to have a sidebar, but the sidebar shouldn't be visible at first visit. If you want to see the sidebar, click "Show Sidebar", save a cookie with the value "expanded"..blablabla.. you get the points, right?

Well, I've downloaded a jQuery cookie plugin and I've the newest jQuery version. My problem is that the plugin won't save my cookies! My jQuery script looks like this.
Code:
$(document).ready(function()
        {
            $("#right_content").hide();
            
            $("#sidebar_toggle").click(function()
            {
                if ($("#right_content").is(":hidden")) {
                    $("#right_content").slideDown("slow");
                    $.cookie("showSidebar", "collapsed");
                    return false;
                } else {
                    $("#right_content").slideUp("slow");
                    $.cookie("showSidebar", "expanded");
                    return false;
                }

                var showSidebar = $.cookie("showSidebar");

                if (showSidebar == "collapsed") {
                    $("#right_content").hide();
                } else {
                    $("#right_content").show();
                }
            });
        });

NOTE: The toggler works perfectly, it just doesn't save my cookie and the sidebar state! Any help? Smile
#2

[eluser]Frank Berger[/eluser]
and here i thought this is a CI Forum, not a jQuery forum..

nevertheless, i don't see any code which actually checks the cookie onload, only on click.. here try this:
Code:
$(document).ready(function()
        {
            
            $("#sidebar_toggle").click(function()
            {
                if ($("#right_content").is(":hidden")) {
                    $("#right_content").slideDown("slow");
                    $.cookie("showSidebar", "collapsed");
                    return false;
                } else {
                    $("#right_content").slideUp("slow");
                    $.cookie("showSidebar", "expanded");
                    return false;
                }
           });
           var showSidebar = $.cookie("showSidebar");
           if (showSidebar == "expanded") {
               $("#right_content").show();
           } else {
               $("#right_content").hide();
           }
            
        });
cheers
Frank
#3

[eluser]IamPrototype[/eluser]
It is a CI forum, but read the categorie description.

It says,
Quote:"Code and Application Development
Use the forum to discuss anything related to programming and code development."

...and this script IS for my CI project.

Anyways I'll try, thanks.
#4

[eluser]tkyy[/eluser]
use the $.post() function to post to a page, and then use codeigniter to set the cookie instead Wink
#5

[eluser]IamPrototype[/eluser]
Huh? Sorry, I'm confused. Smile




Theme © iAndrew 2016 - Forum software by © MyBB