No, but I can show you how to do it very easily ...
Create a separate js file, name it whatever you want, for the convenience of this I will name it jCook.
In your header after adding jQuery add a new file:
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jCook.js"></script>
And below is the EASY code to place in the file:
(function($) { if (!$.setCookie) { $.extend({ setCookie: function(c_name, value, exdays) { try { if (!c_name) return false; var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value = escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString()); document.cookie = c_name + "=" + c_value; } catch(err) { return false; }; return true; } }); }; if (!$.getCookie) { $.extend({ getCookie: function(c_name) { try { var i, x, y, ARRcookies = document.cookie.split(";"); for (i = 0; i < ARRcookies.length; i++) { x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y = ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x = x.replace(/^\s+|\s+$/g,""); if (x == c_name) return unescape(y); }; } catch(err) { return false; }; return false; } }); }; })(jQuery);
Try to catch and that not only helps to guarantee you receive a βfalseβ return if you have something wrong, but in fact it should never be a problem. Using code is easy ...
On your page, where is your download code or something else, follow these steps:
$.setCookie("nameOfCookie", "someValue", 30); // where 30 is the number // of days to expire, or you could leave blank as: $.setCookie("nameOfCookie", "someValue") // And to retrieve your cookie $.getCookie("nameOfCookie");
See how it was !?
And just to solve, the following is an example of a real world to save the state of the selected drop-down menu
$(function(){ $("select[name=somthing]").change(function(e) { $.setCookie("selectThis", $(this).val()); });
SpYk3HH Feb 23 '12 at 19:28 2012-02-23 19:28
source share