blob: 59cfe4f8d11037d401b8f967364b1c4090201912 [file] [log] [blame]
Nils Diewald58141332015-04-07 16:18:45 +00001 <!DOCTYPE html>
2<html>
3 <head>
4 <title>Cookie demo</title>
5 <script src="../src/session.js"></script>
6 <script>
7
8var cookey;
9
10function add (val) {
11 var list = document.getElementById('number');
12 list.textContent += '-' + val;
13 cookey.set('n', list.textContent);
14};
15
16function removeCookie () {
17 cookey.clear();
18};
19
20document.addEventListener('DOMContentLoaded', function () {
21 cookey = KorAP.Session.create('peter');
22 document.getElementById('number').textContent = cookey.get('n') || '';
23
24 var elements = document.getElementsByClassName('num');
25 for (var i = 0; i < elements.length; i++) {
26 elements[i].addEventListener(
27 'click',
28 function (e) {
29 add(this.textContent);
30 }
31 );
32 };
33});
34
35 </script>
36 </head>
37 <body>
38 <div id="number"></div>
39 <span class="num">1</span>
40 <span class="num">2</span>
41 <span class="num">3</span>
42 <div onclick="removeCookie()">remove</div>
43 </body>
44</html>