Make the JS prompt box have no cancel button or turn it off?

  • trent829
  • Born
  • Born
  • trent829
  • Posts: 1

Post 3+ Months Ago

I am trying to password protect a single web page on a website I am designing for a softball organization. Instead of having each member of the team create a profile i have the following code that asks for a password. The password is 'fastpitch2015.'
Code: [ Select ]
function passWord() {
var testV = 1;
var pass1 = prompt('Members Only! Please Enter The Password...',' ');
while (testV < 3) {
if (!pass1)
if (pass1.toLowerCase() == "fastpitch2015") {

var pass1 =
prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
if (pass1.toLowerCase()!="password" & testV ==3)
return " ";

  1. <SCRIPT>
  2. function passWord() {
  3. var testV = 1;
  4. var pass1 = prompt('Members Only! Please Enter The Password...',' ');
  5. while (testV < 3) {
  6. if (!pass1)
  7. history.go(-1);
  8. if (pass1.toLowerCase() == "fastpitch2015") {
  9. alert('Welcome!');
  10. break;
  11. testV+=1;
  12. var pass1 =
  13. prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
  14. }
  15. if (pass1.toLowerCase()!="password" & testV ==3)
  16. history.go(-1);
  17. return " ";
  18. }
  19. window.onload=passWord();
  20. </SCRIPT>
I am wanting to have this script on the page that I am protecting and all I need now is to make it so when someone presses the 'cancel' button or the exit button they either do nothing or they simply re-open the pop-up window so that i can keep people without the password off the page. Please help!
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9193
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

If you are doing anything where you really need to keep outside users off the site, this will not work. Using JavaScript for password protection is extremely easy to break into, in this case all someone has to do is view the source and your password is right there.

I would highly recommend you use password protection via the server itself, your webhost may have a configuration utility to help you do that, or if you are using Apache you can do this typically via a .htaccess file.

With that said if you really want to use JavaScript for this to answer your question it looks like you almost got it by using the while loop. I would just not keep track of how many attempts they did and continue to show the password until they get it right. The main problem here is that some browsers will make another prompt come up if the same thing executes over and over to let them stop the code from running. In this case it would completely break your code.

So with that said instead of doing a while loop you might do a simple if clause that prompts them once. If they get it wrong redirect them to another page on your website that tells them the password is wrong and then links back to the page again for them to try again. You can do that with a simple:

JAVASCRIPT Code: [ Select ]

Hope that helps!

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.