O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example Getting and Setting Cookies

The following code shows a full example of setting and getting cookies. When the code is run, two cookies are set: one for name and the other for language. The cookies are then retrieved from the browser and written to the web page, as shown in Figure 3.2.

01 <html> 02 <head> 03   <title>Python Phrasebook</title> 04   <meta charset="utf-8" /> 05   <script type="text/javascript" 06   src="../js/jquery-2.0.3.min.js"></script> 07   <script> 08     function setCookie(name, value, days) { 09       var date = new Date(); 10       date.setTime(date.getTime()+(days*24*60*60*1000)); 11       var expires = "; expires="+date.toGMTString (); 12       document.cookie = name + "=" + value + ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required