以下のコードは、リダイレクトしようとすると何らかの理由で機能しません。window.location.href など、他の方法をいくつか試しました。機能する唯一のことはwindow.open ("")
、同じにする必要があるときに新しいウィンドウでページを開くことです。もしそうならwindow.open("", "_self")
、それは再び機能しません。を に置き換えるwindow.location
とalert
正常に動作するので、コード全体は正常であり、同じページでのリダイレクトを妨げているだけだと思います。この問題は、私の Windows Chrome と Mac Firefox でも発生します。
<html>
<head>
<script type="text/javascript">
function checkAnswers(){
getElementById("myQuiz");
if(myQuiz.elements[1].checked){
window.location = "www.google.com";
}else{
alert("Failed");
}
};
</script>
</head>
<body>
<img src="Castle.JPG" />
<form id="myQuiz" onsubmit="checkAnswers()" action="">
<p>Name the country this castle is located in?
<br/>
<input type="radio" name="radiobutton" value="A"/>
<label>England</label>
<input type="radio" name="radiobutton" value="B"/>
<label>Ireland</label>
<input type="radio" name="radiobutton" value="C"/>
<label>Spain</label>
<input type="radio" name="radiobutton" value="D"/>
<label>France</label>
<input type="submit" name="submit" value="Submit"/>
<input type="reset" name="reset" value="Reset"/>
</p>
</form>
</body>
</html>