Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    If PW is correct, continue loading page...

    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:

    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!!!

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •