title: Password Page Alert Box
body: <p>I need to put a password protect in one my page. But I want it in a way that when the user click on a menu in my navigation, example is "Gallery", I want an alert box, saying "Enter password to view content" I have used the code below, but it still need to have a button and I don't want that. </p>
  
  <p>P.S. And I prefer to use <strong>javascript</strong> and <strong>html</strong> only. </p>
  
  <pre><code>function passWord() {
     var testV = 1;
     var pass1 = prompt('Enter password to view content',' ');
  
     while (testV &lt; 3) {
        if (!pass1) 
           history.go(-1);
        if (pass1.toLowerCase() == "123456789") {
           alert('You Got it Right!');
           window.open('/gallery');
           break;
        }
  
        testV += 1;
        var pass1 = prompt('Access Denied - Password Incorrect, Please Try Again.','Password');
     }
  
     if (pass1.toLowerCase()!="password" &amp; testV == 3){
        history.go(-1);
        return " ";
     }
  }
  </code></pre>