I'm trying to do a simple password protection for a web page on my site. If some one were to try to go to that protected page without going through the required page, the idea is that it won't load but sent you to the required page to enter the password and proceed properly.
I have the js to do the password, and the js to do the referred page only, but I can't get them to work together. The correct password will have the js send you from "password.htm" to "secret.htm". When I get to "secret.htm" it doesn't see that it just came from "password.htm" therefore I get put into a loop between the two pages.
Here are the js':
"Password js":
var myPassword = prompt('Please enter your password.','');
if (myPassword==null){
var response = window.confirm('Validation failed. Try again?')
if(response){
window.location="please.htm";
}
else {
window.location="index.htm";
}
}
else if (myPassword=='choose one'){
window.location="secret.htm";
}
else {
var response = window.confirm('Validation failed. Try again?')
if(response){
window.location="please.htm";
}
else {
window.location="index.htm";
}
}
**********************************
"Referred page only js":
// Begin
var requiredfrom = "password.htm"; // required prev. page
if (document.referrer.indexOf(requiredfrom) == -1) {
alert("You must come to this page from " + requiredfrom);
window.location=requiredfrom;
}
// End
**********************************
Let me know what I need to change to have this work, please.
Thank you!
I have the js to do the password, and the js to do the referred page only, but I can't get them to work together. The correct password will have the js send you from "password.htm" to "secret.htm". When I get to "secret.htm" it doesn't see that it just came from "password.htm" therefore I get put into a loop between the two pages.
Here are the js':
"Password js":
var myPassword = prompt('Please enter your password.','');
if (myPassword==null){
var response = window.confirm('Validation failed. Try again?')
if(response){
window.location="please.htm";
}
else {
window.location="index.htm";
}
}
else if (myPassword=='choose one'){
window.location="secret.htm";
}
else {
var response = window.confirm('Validation failed. Try again?')
if(response){
window.location="please.htm";
}
else {
window.location="index.htm";
}
}
**********************************
"Referred page only js":
// Begin
var requiredfrom = "password.htm"; // required prev. page
if (document.referrer.indexOf(requiredfrom) == -1) {
alert("You must come to this page from " + requiredfrom);
window.location=requiredfrom;
}
// End
**********************************
Let me know what I need to change to have this work, please.
Thank you!