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 + ...

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.