Do you want to add a cool feature to your website where the title of the page changes when a user tries to exit the page? In this tutorial, we will show you a simple and fun way to achieve this using JavaScript.
Step 1: Create an HTML file
First, create a new HTML file and add the following code to create a basic webpage structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Change Title on Exit</title>
</head>
<body>
<h1>Welcome to my website!</h1>
<p>Don't leave just yet...</p>
</body>
</html>
Save this file as index.html in your project directory.
Step 2: Add JavaScript code
Next, add the following JavaScript code just before the closing
Might learn JavaScript seems cool
That’s pretty cool