How To Create Password Protect Using JavaScript

Good Day!!!

In this tutorial, we are going to learn on How To Create Password Protect Using JavaScript. In the codes below provide a broad password to protect a certain page. Hope you can learn from this tutorial.

Password: nextpage

Directions:

First Step: Kindly save this image to your computer or you can change this whatever you want. Stop SignSecond Step: Copy this code below into the BODY tag of this starting page. (This is the starting page).
  1. <script language="javascript">
  2.  
  3. var nifty_little_window = null;
  4. function passwordStopper() {
  5. nifty_little_window = window.open('home.html', 'theStopper',
  6. 'width=500,height=500,resizable=1');
  7. }
  8.  
  9. </script>
  1. <div>
  2. <h3 class="blink_text">
  3. Click the image below, to login.
  4. </h3>
  5. </div>
  6.  
  7. <img src="image/login.png" class="img_style" onClick="passwordStopper()">
  8. </form>
Third Step: Copy this and kindly save it as a new page. Save it as home.html or you can change this name whatever you want.
  1. <!DOCTYPE html>
  2. Password Stopper
  3. </title>
  4.  
  5. <script language="JavaScript">
  6.  
  7. function Tryit() {
  8. var location;
  9. var password;
  10. password=this.document.testingForm.testingTextBox.value
  11. location=password + ".html"
  12. fetch(location)
  13. theStopper=window.close()
  14. }
  15.  
  16. function fetch(location) {
  17. var root;
  18. if (opener.closed) {
  19. root=window.open('','thePasswordStopper','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no');
  20. root.location.href = location;
  21. } else {
  22. opener.location.href = location;
  23. }
  24. }
  25.  
  26.  
  27. <style type="text/css">
  28. </style>
  29. </head>
  30.  
  31.  
  32. <img src="image/11.gif" width="150" height="150" style="margin-left:170px;">
  33.  
  34. <table border="1">
  35. <tr>
  36. <td><h2 style="text-align:center;">Stop!!! <br /> You'll need a password to go in the next page. <br /> To avoid scam.</h2></td>
  37. </tr>
  38. <tr>
  39. <td>
  40. <form name="testingForm" style="margin:auto; text-align:center;">
  41. <br />
  42. <input type="text" name="testingTextBox" autofocus='autofocus' style="font-size:18px; border-radius:4px; text-indent:5px;">
  43. <br />
  44. <br />
  45. <img src="image/button.png" width="150" height="75" onClick="Tryit(this.form)" style="cursor:pointer;">
  46. </form>
  47. </td>
  48. </tr>
  49.  
  50. </body>
  51.  
  52. </html>
Fourth Step (last step): You're almost done. The above code will be the password protect before going to the final page. The password is nextpage and that would be the filename of our last page or you can change that later and in the below code, this is the last page. Save it as nextpage.html or you can make your own final page.
  1. <!DOCTYPE html>
  2. This is the next page.
  3. </title>
  4.  
  5. <style type="text/css">
  6. </style>
  7. </head>
  8.  
  9.  
  10. <h1 style="text-align:center;">
  11. Welcome!!! You are not a scammer.
  12. </h1>
  13.  
  14. </body>
  15.  
  16. </html>
Note: This script can only protect pages that can end in a .html file or the extension name. You have to double check the extension name too.

Add new comment