Forum Moderators: open
<HEAD>
<SCRIPT language="JavaScript">
<!--hide
var password;
var pass1="cool";
password=prompt('Please enter your password to view this page!',' ');
if (password==pass1)
alert('Password Correct! Click OK to enter!');
else
{
window.location="http://www.example.com/jscript/jpass.htm";
}
//-->
</SCRIPT>
</HEAD>
[edited by: Fotiman at 12:48 am (utc) on Dec. 16, 2009]
[edit reason] Examplified URL [/edit]
2. Don't include HTML comments in your script tag. I'm referring to the lines just below your opening script tag and just above your closing script tag.
3. Microsoft decided that "prompt" introduced a security risk of some kind, and disabled in beginning in IE7. You may get a notice in your browser, but most people won't even notice it. So your alternative is to create your own prompt dialog of sorts. I would recommend checking out the Yahoo UI Library, particularly the SimpleDialog.
4. No URLs please.
5. @chasehx, It is valid to do this:
if (condition) expression;
However, best practice is to always include the curly braces. If you have only one expression to execute, no curly braces needed (but they are still recommended).
Thanks a lot for your advice!
follow your advice, I edit the code as follow:
<script type="text/javascript">
var password;
var pass1="cool";
password=prompt('Please enter your password to view this page!',' ');
if (password==pass1)
{ alert('Password Correct! Click OK to enter!');}
else
{
window.location="test6.html";
}
</SCRIPT>
but still no luck to make it work in the IE. for the YUI, I don't have any experience about it, and now trying to find out how to use it.
would you be able to give me some more instruction please?
Many thanks!
<!-- Sam Skin CSS -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/container/assets/skins/sam/container.css">
<!-- Dependencies -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<!-- Source file -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/container/container-min.js"></script>
Next, apply the yui-skin-sam class name to an element that is a parent of the element in which the SimpleDialog Control lives. You can usually accomplish this simply by putting the class on the <body> tag:
<body class="yui-skin-sam">
Then follow the instructions for creating a SimpleDialog. You'll need to add an input field for capturing the user input. Why don't you give that a try, and if you run into problems or have more questions, post your progress back here.
The .htaccess of the protected directory contains
AuthUserFile /some/path/to/pwd-file/preferably/off/root/.htpasswd
AuthName "This is a protected directory"
AuthType Basic
<Limit GET>
require valid-user
</Limit>
To create the .htpassword for that directory, from the command line enter
htpasswd -c /some/path/to/pfile/preferably/off/root/.htpasswd user-name
And you will be prompted for a password . . . done. The -c flag creates the .htpasswd file. Notable the mention, the file does not HAVE to be named .htpasswd, but it is a hidden file by default if named .htpasswd.
basic authentication tutorial [colostate.edu].
htpaswd documentation [httpd.apache.org]