Created
August 27, 2013 15:57
-
-
Save hsquareweb/6355447 to your computer and use it in GitHub Desktop.
JS: Cookie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Include script after the jQuery library | |
| // https://github.com/carhartl/jquery-cookie | |
| // <script src="/path/to/jquery.cookie.js"></script> | |
| //set cookies | |
| $("#div").toggle(function() { //create div toggle | |
| $("#div").slideUp("slow"); //create effect | |
| $.cookie('cookie_name', 'value', {expires: 7}); //set cookie expire in 7 days | |
| }, | |
| function () { //continue the toggle | |
| $("#div").slideDown("slow"); //create effect | |
| $.cookie('cookie_name', 'value'); //set cookie | |
| }); | |
| //get cookie | |
| alert( $.cookie("cookie_name") ); | |
| //check for cookies | |
| var cookie_name = $.cookie('cookie_name'); //set cookie var | |
| if (cookie_name == 'value') { //if equals this val | |
| $("#div").hide(); //do this | |
| }; | |
| //check for null cookies | |
| var cookie_name = $.cookie('cookie_name'); //set cookie var | |
| if (cookie_name == null) { // if empty | |
| $("#div").hide(); //do this | |
| }; | |
| //null cookies, same as getting | |
| $.cookie("cookie_name", null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment