]> git.lizzy.rs Git - html-collection.git/blob - cookies.html
Add LICENSE
[html-collection.git] / cookies.html
1 <html>
2 <head>
3 <meta charset="utf-8">  
4 <title>Cookies</title>
5 <script>
6 var text="";
7 function init() {
8         if(document.cookie){
9 text=document.cookie.split(',');
10 document.getElementsByName('ein')[0].value="";
11 document.getElementsByName('ein')[1].value="";
12 if(window.prompt("Password:")===text[1]){
13 ausgabe(text[0]);
14 }       
15 else{
16         window.alert("Wrong. Resetting Cookie.");
17         document.cookie = ""; 
18         ausgabe("none");
19         }
20 }
21 }
22 function eingabe(){
23 document.cookie=[document.getElementsByName('ein')[0].value,document.getElementsByName('ein')[1].value];        
24         }
25 function ausgabe(text) {
26   var ausgabe = document.getElementsByName('anzeige')[0];
27   ausgabe.innerHTML = text;
28 }
29
30 window.addEventListener('DOMContentLoaded', init);
31 </script>       
32 </head>
33 <body>
34 <h1>Use a cookie to save data.</h1>
35 Content Last Time:
36 <p name="anzeige"></p>
37 <br><br>
38 Content:
39 <br>
40 <textarea name="ein"></textarea>
41 <br>
42 Password: 
43 <br>
44 <input name="ein">
45 <button onclick="eingabe();">Save</button><br>
46 </body>
47 </html>