visits

 <!DOCTYPE html>

<html>
<head>
    <title>Visit Counter</title>
</head>
<body>
    <p>Page Visits</p>
    <p>Total Visits: <span id="total-visits">0</span></p>
    <p>Visits Today: <span id="today-visits">0</span></p>
 
    <script>
        // Function to update the visit count
        function updateVisitCount() {
            // Retrieve the total visits from local storage (you can use a server-side solution for more robust tracking)
            let totalVisits = localStorage.getItem('totalVisits') || 0;
 
            // Retrieve today's visits from local storage
            let todayVisits = localStorage.getItem('todayVisits') || 0;
 
            // Get the current date
            let currentDate = new Date().toDateString();
 
            // Check if the user has visited today
            if (localStorage.getItem('lastVisitDate') === currentDate) {
                todayVisits = parseInt(todayVisits) + 1;
            } else {
                todayVisits = 1;
                localStorage.setItem('lastVisitDate', currentDate);
            }
 
            // Update the total and today visit counts
            totalVisits = parseInt(totalVisits) + 1;
            localStorage.setItem('totalVisits', totalVisits);
            localStorage.setItem('todayVisits', todayVisits);
 
            // Display the visit counts on the page
            document.getElementById('total-visits').textContent = totalVisits;
            document.getElementById('today-visits').textContent = todayVisits;
        }
 
        // Call the updateVisitCount function when the page loads
        updateVisitCount();
    </script>
</body>
</html>
 

© 2024 All Rights Reserved Terms of Use and Privacy Policy