user3686107
user3686107

Reputation: 25

Click counter without javascript

I'm using this javascript for a click counter in my blogger blog:

    function clickCounter() {
if(typeof(Storage) !== "undefined") {
    if (sessionStorage.clickcount) {
        sessionStorage.clickcount = Number(sessionStorage.clickcount)+1;
    } else {
        sessionStorage.clickcount = 1;
    }
    document.getElementById("result").innerHTML = "Correct! " + sessionStorage.clickcount + " Smart answers 'til now.";
} else {
    document.getElementById("result").innerHTML = "Sorry, your browser does not support this quiz...";
}

}

<button onclick="clickCounter()" type="button">Suspension</button>

Is there any way to create something similar through a non javascript method?

Can you help me triger an event (extra text message through popup or within the page) every 5, 10, 20, 100 clicks?

Thank you very much

Upvotes: 0

Views: 875

Answers (2)

bmb
bmb

Reputation: 6248

I have not tried this but...

What if you put multiple buttons positioned on top of each other. As each one is clicked, it can be made to vanish with something like

a:visited { display: none; }

The ones that need to display a message (5th, 10th, etc.) have different behavior attached.

See on click hide this (button link) pure css

Upvotes: 1

Jeremy J Starcher
Jeremy J Starcher

Reputation: 23863

HTML, and the Web in general, was designed to be stateless.

When you pull up a page, it should be like the first time -- and every time -- you pull up the page.

Since then, people have come up with a number of techniques to add state -- to save data, but they all involved one of two methods -- or sometimes both.

Method 1: Store state on the server.

This method uses HTML forms or cookies to slip information to the server when you load and reload a page.

Method 2: Store state in the client

While there are some older versions of Internet Explorer that can be coded in VBA, we are going to ignore that. The only "real" way to run any kind of code on the client, to store any data, is to use JavaScript.

Method 3: Use the client to talk to the server

Using Ajax, you can let your client talk to the server, but without doing a page reload. This still uses JavaScript.

So, to answer your question:

  • Without a server
  • Without JavaScript

No, you cannot save or store anything.

Upvotes: 2

Related Questions