Advertisement
Mihao

Zadanie z cookies dla uczniw

Mar 19th, 2022
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.91 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.  
  5.     </head>
  6.  
  7.     <body>
  8.  
  9.         <button type="button" onclick="dodajCookie()">
  10.             Dodajc Cookie
  11.         </button>
  12.  
  13.         <button type="button" onclick="pokazCookie()">
  14.             Pokaz cookie
  15.         </button>
  16.  
  17.         <button type="button" onclick="zwiekszLicznik()">
  18.             zwieksz licznik
  19.         </button>
  20.        
  21.         <script>
  22.             function dodajCookie(){
  23.                 document.cookie="licznik=0;expires=Wed, 18 Dec 2030 12:00:00 GMT";
  24.             }
  25.  
  26.             function odczytajCookie(name){
  27.                 var v = document.cookie.match(
  28.                     '(^|;)' + name + '=([^;]*)(;|$)');
  29.                 return v ? v[2] : null;
  30.             }
  31.  
  32.             function pokazCookie(){
  33.                 alert(odczytajCookie("licznik"));
  34.             }
  35.  
  36.             function zwiekszLicznik(){
  37.                 var licznik = odczytajCookie("licznik");
  38.                 licznik = parseInt(licznik, 10);
  39.                 licznik = licznik + 1;
  40.                 document.cookie="licznik="+ licznik +
  41.                 ";expires=Wed, 18 Dec 2030 12:00:00 GMT";
  42.             }
  43.         </script>
  44.  
  45.     </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement