JavaScript From JavaScripts.com
This is the JavaScript that will give you the pop-up box so people can't ever see your page unless they know the password. You can see it for yourself, it's called password protection that actually works. Copy and paste it into your text editor or HTML editor so you can follow along with these instructions.
Here are some things you can or need to change in this password code to make it work:
- Right after the <script> tag you see a line that starts with the word alert. Inside the parenthesis and quotes is a statement that says "the password is enter". You can change this statement to anything you want it to say, or you can take the whole line out altogether if you don't want that pop-up box.
- The next thing you will want to change is the password. You can find it in the line that says var ans="enter". Change the word enter to whatever you want your password to be.
- The next thing you can change, if you want to, is the line that says alert("wrong you will now be transfered"). If you don't like the words "wrong you will now be transfered" then change it to what you want it to say. This is the pop-up box your reader will see if they get the password wrong before they are transferred to the page you assign them to go to.
- On the line that says window.location="http://yahoo.com" you can assign the page they go to when they get the password wrong. Just change "http://yahoo.com" to the page you want them to go to.
- On the line that says };else {alert("correct"); }; you can change the word "correct" to whatever you want the reader to see if they get the password correct before they are transferred to the page they want to get to.
- Last but not least. You will need to change this line for every page you put this code on. On the line that says };else {window.location="http://yahoo.com" }; you need to change "http://yahoo.com" to the URL of the page you put this code on or the URL of a page you want them sent to when they get the password right.
Passwords are fun and sometimes necessary. I hope this password Javascript will help you add passwords to your Web pages and keep them safe and secure from people you don't want to see them. Remember to give the password to the people you do want to see the Web pages. They won't be about to get in without the password once you add this JavaScript.

