Window self Property - counts the number of times a user has clicked a button, in the current session: - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window self

Description

Window self Property - counts the number of times a user has clicked a button, in the current session:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script>
function clickCounter() {/*w  w  w  . j  a v  a 2  s  .  c o m*/
    if(typeof(Storage) !== "undefined") {
        if (sessionStorage.clickcount) {
            sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
        } else {
            sessionStorage.clickcount = 1;
        }
        document.getElementById("result").innerHTML = "You have clicked the button " + sessionStorage.clickcount + " time(s) in this session.";
    } 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>
</body>
</html>

Related Tutorials