post your comment   print   send to a friend
Rate:  41% | Views: 1722
Question categories:  Unix Plans

How do I password protect a webpage using JavaScript?

Answer by: Kristen Jourdonais, Aplus.Net Knowledge Base Support

One way to password protect a single webpage on your site is by using JavaScript. This will only permit access to users that you want viewing your page. This is a simple solution for protection of a single page. Here is how to set up a password protected page on your webspace:

  1. Open a basic text editing program, like Notepad, WordPad, etc. Begin by typing the opening tags: <html><head>
  2. Type the title of your page and close the title with a tag. For example: <title>Protected Page: Please enter password</title>
  3. Type the following:  <script language="Javascript"> (This command tells the browser a script is about to begin.)
  4. Press the Enter key and type the following: //prompt. Press the Enter key again.
  5. Enter the prompt by typing the following: var password = prompt("Enter in the password""");  (There are three double-quotation marks after the word "password" and a semicolon after the last parentheses.)
  6. Type the following, replacing "pass" with the word or numbers the password will be: if (password == "pass")
  7. Now type the following, replacing "correct.html" with the name of the page the correct user is directed to: {location = "correct.html"} (This tells the browser to send the user who enters the correct password to this page.)
  8. Send users who type the incorrect password to an error page by typing the following, replacing "error.html" with the error page you have created: else {location = "error.html"}
  9. End the script by typing the following: //--></script>
  10. Close the scripted section of the page by typing the follow: </head>
  11. Add a body section for browsers that do not read JavaScript: <body>This page is designed for viewing by Netscape 2.0, Internet Explorer 3.0 or above. Please upgrade your browser and return soon!</body>
  12. Close the Web page by typing: </html>
  13. Save the page (for example, save it as "password.html").

When a visitor enters the correct password, they are taken to the protected page. If they are not, they will be taken to the page that you have designated as your error page (called "error.html" in this document).

Customer Feedback
Rate:  41% | Views: 1722 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Webpage Design | Custom Design    Back to serch results
Browse the Base
Knowledge Base
Shared Hosting
  Unix Plans
    MySQL
Messages
 

$75 Free Google AdWords

Free $75 Google AdWords when you sign up for WebImage! Target by location, create your own, or let Google create your ads for you. Check out http://www.aplus.net/google.html to see how AdWords works for you.

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. I have a Unix-based shared hosting plan. How can I change permissions for files/directories using the File Manager?
 
2. How can I protect directories?
 
3. How to Set Up a Storefront ?
 
4. What are the permissions on files and directories?
 
5. In Unix, what is the find command, and how do I use it to search through directories for files?
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest