Universal click tracker logging clicks from all users across the globe

I am new to CSS, HTML, and JS, but I have a unique idea for a click counter that counts the total clicks made by all users.

For example, if the counter is at "0" and person A clicks once, then person B also clicks once, the result should show as "2" instead of "1".

I have researched how to create the counter, but most solutions I found reset the count when the page is reloaded, which is not what I want.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Click Counter App</title>
<!-- ---------------- linked css file ----------------- -->
<link rel="stylesheet" href="click-counter.css">

</head>
<body>

    <!-- ----------------html formated --------------- -->

<div class="container">
    <main>
        <h1>Click Counter App</h1>
        <div class="button-counter">
            <button class="btn decreased"> - </button>
            <span> 0 </span>
            <button class="btn increase"> + </button>  
        </div>
    </main>
</div>





<!-- ---------------- linked js file ---------------- -->
    <script src="click-app.js"></script>
    
</body>
</html>


    // initial value of span ========  

let value = 0 

// getting value by reference ==========

const span = document.querySelector("span");
const decreased = document.querySelector(".decreased")
const increase = document.querySelector(".increase");


// --------- calling the even function -------------------

decreased.addEventListener("click" , () => {
    span.innerHTML=value--;

});

// --------------- event for increase button--------------------

increase.addEventListener("click" , () =>{
    span.innerHTML=value++;
})
    

*{
    margin 0%;
    padding: 0%;
    box-sizing: border-box;
    background-color: rgba(255, 166, 0, 0.644);

}
.container
{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: orange;
    border: 1px solid orange;
    border-radius: 20px;
    box-shadow: 5px 5px 4px 2px rgb(211, 161, 96);
    width: 300px;
    height: 200px;

}

h1{
    font-size: 30px;
    text-align: center;
    text-shadow: 2px 2px rgba(5, 5, 5, 5);
    color: white;


}

.button-counter{
    display: flex;
    justify-content: space-around;
    align-items: center;
    
}
button
{
    text-align: center;
    padding: 10px;
    margin: 10px;
    font-size: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: rgba(255, 166, 0, 0.445);
    cursor: pointer;
    box-shadow: 5px 5px 5px rgba(255, 166, 0, 0.829);
    border: 1px solid rgb(231, 230, 230);
    font-weight: bolder;
    color: white;
    

}
button:hover{
    background-color: #fff;
    color: black;

}
span
{
    text-align: center;
    box-shadow: 5px 5px 4px 2px rgb(150, 143, 121);
    font-size: 32px;
    font-weight: bolder;
    
    border-radius: 10px;
    width: 50px;
    border: 1px solid rgb(90, 89, 89);
    color: rgb(36, 17, 33);

}

Answer №1

In order to continue counting from where the previous user left off, you must save the data in a storage location such as a database. Upon loading the page, retrieve and display this value to the next user.

Unfortunately, it is not possible to achieve this using just CSS, HTML, and JS.

Answer №2

Storing public data on the frontend can be effectively done using local storage.
window.localStorage.setItem(name, data); // -> set item
window.localStorage.getItem(name); // -> get item

Drawbacks

  • Potential for alteration through DevTools
  • Data reset upon cache clearance

If you want to avoid these issues, utilizing a database and backend is necessary.

UPDATE: A database and server are essential for sharing data across multiple users and/or clients.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a hiccup during a join linq query操作oops!

I am currently working on this code snippet: public ActionResult JoinSupToPro() { SupplierDBContext dbS = new SupplierDBContext(); var innerJoinQuery = from pro in db.Products join sup in dbS.Suppliers on pro.SupplierId equals sup ...

Personalized jQuery Slider with automatic sliding

I am currently working on creating my own image slider without relying on plugins. 1st inquiry : How can I achieve horizontal animation for the slider? 2nd inquiry : I want the images to cover both the height and width of their container while maintainin ...

Exploring the Possibilities of Manipulating HTML Tables with CSS

Looking for a solution to rearrange the layout of a html table with 2 cells in a row? Want to make the second cell appear below the first one instead of next to it using only CSS? It may require a bit of a "dirty hack", but the desired outcome is still n ...

Arranging a nested JSON array directly

Below is the structure of my JSON data : Root |- cells [] |-Individual cells with the following |- Facts (Object) |- Measures (Object) |- Key value pairs |- other valu ...

I attempted to pull information from the database and display it in my checkboxes. However, I encountered an issue where I am unable to save the selected checkboxes back to the database

This code snippet is written in Blade for a reservation form: <div class="col-lg-6"> <div class="contact-form"> <form id="contact" action="{{url('/reservatio ...

Combine the object with TypeScript

Within my Angular application, the data is structured as follows: forEachArrayOne = [ { id: 1, name: "userOne" }, { id: 2, name: "userTwo" }, { id: 3, name: "userThree" } ] forEachArrayTwo = [ { id: 1, name: "userFour" }, { id: ...

HTML/CSS: Issue with image grid layout where images of different heights are not wrapping correctly

I have a Wordpress-based web project in progress at the following link: The current setup of the post thumbnails grid on the website was done with the assumption that all thumbnails will be the same height. However, I am looking to modify it so that the t ...

Creating mobile-friendly websites for a variety of devices, including smartphones and tablets

Creating a prototype webpage for my friend, one crucial aspect is ensuring it looks good on different devices. Utilizing Bootstrap, I've implemented vertical collapsing for certain elements, but I'm struggling with how to adjust other components ...

Creating a virtual reference in Mongoose that connects two ObjectIds

Is it possible to establish a virtual reference using a local ObjectId to a foreign ObjectId, or can it only be done with a local _id? I'm troubleshooting to determine if there's an issue causing this not to work as expected. const Post = new mo ...

Manage the expiration date of an external JavaScript file utilized on a website

To make sure the JavaScript file expires on a web page, can anyone address these specific questions: Will the script file expire when the page expires? Is it advisable to include a version number in the names of script files (and HTML pages)? If there ...

Utilizing getStaticProps for Performance Optimization in Next.js

I am currently in the process of setting up a blog using Next.js and GraphCMS. I have an ArticleList component that I want to display on multiple pages, such as my homepage and under each article as a recommendation. Since the article list is sourced from ...

Is it possible to use jQuery FullCalendar to visually highlight specific time ranges in order to indicate to users that they are selectable?

My application has dynamic selectable time ranges. For example, on Mondays, users can only select times from 12:00 to 14:00, and on Thursdays from 17:00 to 19:00, and so on. While I can handle the select event to restrict user input, I would like to visua ...

I am encountering challenges with integrating procedural terrain generation on my three js project

Hello there friends, I've discovered a fantastic library for procedural terrain generation called https://github.com/IceCreamYou/THREE.Terrain. I'm excited to incorporate this into my code! Insert your code below: const scene = new THREE.Scene ...

Issues with displaying charts have been reported for generator-angular-fullstack and angular-chart.js

After working with Angular for some time, I decided to give Yeoman and generator-angular-fullstack a try. My main goal was to use angular-chart.js to display a chart in a particular view called poll.html. Surprisingly, everything loaded correctly except fo ...

Strategies for eliminating _next folder from file path within the build directory of Next Js

Is there a way to eliminate "_next" from the path in the build folder for Next Js version 13.2.4? For reference, here is an example: We would greatly appreciate any assistance on this matter. ...

Unpredictable jQuery Ajax setTimeout

I have a script that retrieves data from ajax.php and displays it in a div. The intention is for the information to be shown for a period of 3 seconds before hiding the #ajax-content and displaying #welcome-content. Most of the time it works as intended, ...

Why do certain URLs bypass the filters despite not meeting the criteria in the Chrome extension?

I am currently developing a Chrome extension that is designed to automatically close tabs when specific URLs are visited, helping me stay focused and avoid distractions. The list of sites that should trigger tab closures includes: YouTube Facebook Reddit ...

What is the reason behind the cross-origin error thrown by JSON.parse?

When I don't use JSON.parse, my code works perfectly fine. However, as soon as I attempt to parse or stringify my data object, a cross-origin error is thrown. Why is this occurring and what steps can I take to resolve it? The snippet of code in Title ...

What are the reasons behind loading failures and the subsequent failure to resolve promises?

Here is a snippet of code that is part of a larger directive: var imageArray = []; for (var i = 0; i < $scope.abbreviations.length; i++) { imageArray[i] = new Image(); imageArray[i].src = $scope.abbreviations[i].img ...

Using Jquery to create a slideshow with a div that is set to absolute

<!DOCTYPE html> <html> <head> <script> $(document).ready(function(){ $("#flip").click(function(){ $("#panel").slideDown("slow"); }); }); ...