...

View Full Version : If PW is correct, continue loading page...



lilqhgal
05-07-2007, 05:27 PM
I have a javascript file that loads a specified URL when the "correct" password is entered, or a different specified URL when the "wrong" password is entered. Here's the code:



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

var password;
var pass1 = "PASSWORD"; // place password here

password=prompt("What's the password?","");

if (password==pass1) {
window.location= "page.html"; // file to open if password is correct
} else {
window.location= "wrongpass.html"; // file to load if password is incorrect
}
// End -->
</script>


However, I want to enter this into a content management system that displays intro text from the content item, and when clicking the link to the full story, I want this javascript to load. Therefore, the user will see the intro text, a link, but will be required to enter the specified password to see the rest of the story. The problem with this, is when the javascript is inserted into the full story itself, upon clicking the link, the page loads the password prompt, you enter the correct password, and then you are "redirected" to the very same full story page again, and you get stuck in an enter-the-password loop. Is there some way to modify that script above to instead of "redirecting" the good password to a url, to have it say "continue loading this page's contents" instead? Thanks much!!!

lilqhgal
05-07-2007, 05:39 PM
Nevermind! I found one! (Why is it I search for 45 minutes to an hour, dont find anything, post in a help form, and minutes later find my own answer....???)

This is the js I used:



<script type="text/javascript">
<!-- BEGIN Script

var wrong="redirect.htm"; // where to go if wrong password...

var password="WHAT"; // password... change to whatever you wish to use...

var name = prompt("Please type in the password",''); // prompts the user this...

if (name == password) {(confirm("Welcome!"))} // if... else statement... right, confirm this, wrong, go to wrong...
else {location.href=wrong}
// END Script -->
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum