• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Passwords / Password Protect

Password Protect

Password Protect

Use this script to protect online files. Users cannot cancel out of it. It can also be used with your browser’s home page to control Internet access on your own computer.

Copy the coding into the HEAD of your HTML document:

<script type=”text/javascript”>
<!– Begin
/* This script and many more are available free online at
The JavaScript Source :: http://javascriptsource.com
Created by: Javascript Newbie :: http://expage.com/javascriptnewbie
*/

var password;
var pass1 = “password”; // place password here

password=prompt(“Please enter your password:”,””);

if (password==pass1) {
  window.location= “test2.html”; // file to open if password is correct
} else {
  window.location= “test.html”; // file to load if password is incorrect
}
// End –>
</script>

<p><center>
<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>
by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>
</center><p>

Passwords

Related Snippets:

  • Toggle password visibility

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers