LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-01-2022, 02:12 PM   #1
PsychoHermit
Member
 
Registered: Aug 2021
Location: Carson City Nevada
Distribution: Debian Testing
Posts: 138

Rep: Reputation: Disabled
Javascript question


Greetings folks,

This isn't really a Linux question so forgive me for posting it but I m stumped and don't know where to turn. I have a web page and am trying to make a hit counter. I have it inside of <script></script> tags. The file count.txt is world writable. Any assistance would be most welcome.

Thanks in advance.
--glenn

Code:
// Requiring fs module in which
// writeFile function is defined.
const fs = require('fs');

var visitCount = fs.readFile('count.txt');
visitCount = Number(visitCount) + 1;
fs.writeFile('count.txt' visitCount err);
 if (err) throw err;
mods, please move this to the programming forum

Last edited by PsychoHermit; 10-01-2022 at 04:08 PM.
 
Old 10-02-2022, 10:34 AM   #2
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
Quick example:

hc.html
Code:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div>
        <p>The number of visitors is : <span id="cntr">0</span></p>
    </div>

    <script>
    function counter_fn() {
        var counter = document.getElementById("cntr");
        var count = 0;
        count = parseInt(counter.innerHTML);
        count = count + 1;
        counter.innerHTML = count;
    }
    window.onload = counter_fn
    </script>
    
   <button onclick = "counter_fn()"> Reload </button> 
</body>
</html>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: JavaScript creator Eich's latest project: KILL JAVASCRIPT LXer Syndicated Linux News 0 06-18-2015 08:30 AM
Looking for Textbrowser with JavaScript Support or Elink Javascript Support rohezal Linux - Software 4 09-01-2009 01:02 PM
Ubuntu Edgy/Firefox 2/Javascript - Firefox closes accessing websites with Javascript Interdictor Ubuntu 8 11-02-2006 11:58 AM
Javascript question? mikeshn Programming 2 08-22-2002 03:44 PM
JavaScript Question vance Programming 2 04-14-2002 12:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration