Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script>
- function clickCounter() {
- if(typeof(Storage) !== "undefined") {
- if(isNaN(parseInt(localStorage.tens))) {
- localStorage.tens = 0;
- }
- if(isNaN(parseInt(localStorage.clickcount))) {
- localStorage.clickcount = 0;
- }
- if (localStorage.clickcount < 10) {
- localStorage.clickcount = Number(localStorage.clickcount) + 1;
- } else {
- localStorage.clickcount = 1;
- localStorage.tens = Number(localStorage.tens) + 1;
- }
- document.getElementById("result").innerHTML = "You have clicked the button " + localStorage.clickcount + " time(s).";
- document.getElementById("tens").innerHTML = "Tens: " + localStorage.tens;
- } else {
- document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
- }
- }
- </script>
- </head>
- <body>
- <p><button onclick="clickCounter()" type="button">Click me!</button></p>
- <div id="result"></div>
- <div id="tens"></div>
- <p>Click the button to see the counter increase.</p>
- <p>Close the browser tab (or window), and try again, and the counter will continue to count (is not reset).</p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment