2017-11-06 8 views
-1

構文の変更やwindow.promptの使用を含む多くのバリエーションを試しましたが、プロンプトを表示する方法が見つかりません。プロンプトコマンドがHTML5で動作しない

注:私の他のコード(html)にエラーがある場合は、それらを指摘してください。ただし、JSに焦点を当ててください - ページにはすべての要素が完全にロードされています。私はプロンプトを持っていなかったときにそれが完璧に走ったにもかかわらず、手伝ってくれませんか?

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="utf-8"> 
<meta name="viewport" content="width=device-width"> 
<title>program</title> 
    <link href="index.css" rel="stylesheet" type="text/css" /> 
    </head> 
    <body> 
<script> 
     var accesskey="config"; 
     if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera 
Mini/i.test(navigator.userAgent)) { 
var attempt=window.prompt("Mobile browsers are not currently supported. If 
you are a developer, enter the access key.") 

     if(accesskey!=attempt) 
     { 
      alert("Bye!"); 
      window.location("https://google.com); 
     } 
        else 
        { 
        console.log("Authenticated"); 
        } 
    } 
    </script> 
    </body> 
</html> 
+3

実際に正規表現内と文字列内に改行がありますか?また、 'window.location'は関数ではなく、' ''が閉じていません。 – Xufox

+1

また、 'window.location();の' ''を閉じていません。 –

+0

@Xufoxはい、あります。 –

答えて

2
  • を行う必要がありますあなたはあなたの正規表現とpromptで改行/スペースの数を持って閉じ"とそのプロパティではありません機能が不足していますメッセージ。
  • window.locationは関数ではありません。単純にURLを割り当てます。
  • google.comの最後に、"のクローズがありません。これらの3つの問題を修正

は、次の作業の例を生成します。

var accesskey = "config"; 
 
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { 
 
    var attempt = window.prompt("Mobile browsers are not currently supported. If you are a developer, enter the access key.") 
 
    if (accesskey != attempt) { 
 
    alert("Bye!"); 
 
    window.location = "https://google.com"; 
 
    } else { 
 
    console.log("Authenticated"); 
 
    } 
 
}

・ホープ、このことができます! :)

1

プロンプトは、あなたのregex持っている改行以下のように働いているともその偽ので、私はここに真であることを余儀なくされています。 もwindow.location("https://google.com);あなたはwindow.location="https://google.com"

var accesskey="config"; 
 
if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || true) 
 
var attempt=window.prompt("Mobile browsers are not currently supported. If you are a developer, enter the access key.") 
 

 
     if(accesskey!=attempt) 
 
     { 
 
      alert("Bye!"); 
 
      window.location ="https://google.com"; 
 
     } 
 
        else 
 
        { 
 
        console.log("Authenticated"); 
 
        }
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<meta name="viewport" content="width=device-width"> 
 
<title>program</title> 
 
    </head> 
 
    <body> 
 
    
 
    </body> 
 
</html>

+0

役に立ったと答えてマークしてください –

+0

瞬時にエラーに遭遇します。間違ったコードやヌルコードを入力してもGoogleに行くことなくウェブサイト自体にリダイレクトされます。私をデバッグさせてください。 –

+0

あなたはどんなエラーを受けているか教えてください...それは同じ起源の問題かもしれません –

関連する問題