Guest User

Untitled

a guest
Jun 29th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script>
  5. function clickCounter() {
  6.  
  7. if(typeof(Storage) !== "undefined") {
  8.  
  9. if(isNaN(parseInt(localStorage.tens))) {
  10. localStorage.tens = 0;
  11. }
  12. if(isNaN(parseInt(localStorage.clickcount))) {
  13. localStorage.clickcount = 0;
  14. }
  15.  
  16. if (localStorage.clickcount < 10) {
  17. localStorage.clickcount = Number(localStorage.clickcount) + 1;
  18. } else {
  19. localStorage.clickcount = 1;
  20. localStorage.tens = Number(localStorage.tens) + 1;
  21. }
  22. document.getElementById("result").innerHTML = "You have clicked the button " + localStorage.clickcount + " time(s).";
  23. document.getElementById("tens").innerHTML = "Tens: " + localStorage.tens;
  24. } else {
  25. document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
  26. }
  27. }
  28. </script>
  29. </head>
  30. <body>
  31. <p><button onclick="clickCounter()" type="button">Click me!</button></p>
  32. <div id="result"></div>
  33. <div id="tens"></div>
  34. <p>Click the button to see the counter increase.</p>
  35. <p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p>
  36. </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment