| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>Cookie demo</title> |
| <script src="../src/session.js"></script> |
| <script> |
| |
| var cookey; |
| |
| function add (val) { |
| var list = document.getElementById('number'); |
| list.textContent += '-' + val; |
| cookey.set('n', list.textContent); |
| }; |
| |
| function removeCookie () { |
| cookey.clear(); |
| }; |
| |
| document.addEventListener('DOMContentLoaded', function () { |
| cookey = KorAP.Session.create('peter'); |
| document.getElementById('number').textContent = cookey.get('n') || ''; |
| |
| var elements = document.getElementsByClassName('num'); |
| for (var i = 0; i < elements.length; i++) { |
| elements[i].addEventListener( |
| 'click', |
| function (e) { |
| add(this.textContent); |
| } |
| ); |
| }; |
| }); |
| |
| </script> |
| </head> |
| <body> |
| <div id="number"></div> |
| <span class="num">1</span> |
| <span class="num">2</span> |
| <span class="num">3</span> |
| <div onclick="removeCookie()">remove</div> |
| </body> |
| </html> |