Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6954105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:33:47+00:00 2026-05-27T14:33:47+00:00

I can’t seem to figure out how to correct the 2 problems I’m running

  • 0

I can’t seem to figure out how to correct the 2 problems I’m running into.

Here is the code I am working with:

function password() {
    var testV = 1;
    var pass1 = prompt('Please Enter The Password','');
    while (testV < 2) {
        if (!pass1) 
            history.go(-1);
        if (pass1 == "default") { //password here
            window.open('http://www.[redacted].com/downloads/documents/12-2011-project.psd'); //if password correct
            break;
        } 
        testV += 1;
        var pass1 = 
            prompt('Incorrect - Please Try Again.',''); //if password incorrect
    }
    if (pass1 != "password" & testV == 2)               
        history.go(-1);
    window.location = "/exit.html"; //redirects to here after success and opens download
}

My first problem:
When clicking “Cancel” it prompts again. I just want it to simply disappear after I click cancel.

Second:
After the 2 attempts are used when you click “Cancel“, it redirects as if downloaded (no download is activated, which is good.)

What am I doing wrong, or what needs to be fixed?

Also, If a user just presses “OK” twice, there is no download activated, but it still redirects. I left a note on the exit page stating this. This doesn’t bug me, but can that be fixed?; if not that’s fine with me.

SOLVED (12/16 @ 9:30 AM)
Thanks to all that answered my first question!.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:33:48+00:00Added an answer on May 27, 2026 at 2:33 pm

    Problem 1 – If I understand you correctly, if the user cancels you want to abort all further processing so you can simply return from the password() function by changing this:

    if (!pass1) 
      history.go(-1);
    

    To this:

    if (!pass1) {
      history.go(-1);
      return;
    }
    

    Otherwise if you want to stay in your function say break instead of return (as you already do for the correct password) to get out of the while loop and then add the appropriate if structure for that situation after the loop.

    Problem 2 – No redirect will occur if you’ve already returned out of your password() function as shown above. If you’re trying to cater for when the user has not cancelled but has gotten the password wrong then something like this:

    if (pass1 != "password" & testV == 2)               
        history.go(-1);
    else
        window.location = "/exit.html";
    

    Though I’m not sure why you’re testing the value of testV at that point.

    Note: If you’ve got passwords in your JavaScript the user will be able to see the passwords by viewing your JS source.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can someone explain the usage of the dollar sign here.. var updateProgressDiv = $get('updateProgressDiv');
can any one tell me how can change this java code into objective c.is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
I am currently running into a problem where an element is coming back from
Can i get the source code for a WAMP stack installer somewhere? Any help
Can't work out a way to make an array of buttons in android. This
Can we put functions to determine the condition for our list comprehensions. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.