2016-06-15 1 views
-3

javascriptとifループを使用してパスワードを確認しています。ただし、javascriptではない文字列を入力すると、アラートは表示されません。ここに私のコードです。Javascript Password Checker

<script type = "text/javascript"> 
function password_prompt() { 

    var password = window.prompt("Please enter the correct password ", ""); //password = javascript 
    if (password == "javascript") { 
    var x = window.confirm("Please confirm you want to enter the webpage!"); 
     if (x != 1) { 
     window.close(); 
     window.open("https://www.google.com/"); 
    } 
    if (password != "javascript") { 
     window.alert("You entered the wrong password! Page will now close!"); 
    window.close(); 
    window.open("about:blank"); 
     } 

    } 
} 
</script> 
+8

インデントあなたのコードとあなたが表示されます – BeyelerStudios

+2

OT:JavaScriptの真偽、このような悪い考えでは... :) –

+2

ハードコードパスワードは悪い考え –

答えて

-1

<script type = "text/javascript"> 
 
function password_prompt() { 
 

 
    var password = prompt("Please enter the correct password ", ""); //password = javascript 
 
    if (password == "javascript") { 
 
    var x = confirm("Please confirm you want to enter the webpage!"); 
 
     if (x != 1) { 
 
     window.close(); 
 
     window.open("https://www.google.com/"); 
 
    } 
 
    if (password != "javascript") { 
 
     alert("You entered the wrong password! Page will now close!"); 
 
    window.close(); 
 
    window.open("about:blank"); 
 
     } 
 

 
    } 
 
} 
 
</script>

+0

http://www.w3schools.com/jsref/met_win_prompt.aspのドキュメント –

+0

何かjavascriptとは違う、警告が表示されない –

+0

パスワード値が "javascript"と等しくない場合、パスワードの現在の値 –

-1
<script type = "text/javascript"> 
function password_prompt() { 

    var password = window.prompt("Please enter the correct password ", ""); //password = javascript 
    if (password == "javascript") { 
     var x = window.confirm("Please confirm you want to enter the webpage!"); 
     if (x != 1) { 
      window.close(); 
      window.open("https://www.google.com/"); 
     } 
    } 
    if (password != "javascript") { 
     window.alert("You entered the wrong password! Page will now close!"); 
     window.close(); 
     window.open("about:blank"); 
    } 
} 
</script>