admin管理员组文章数量:1312931
I need to redirect to another page based on the number of certain moves. For example: if the number of moves after you find all the pairs are between 4 - 8, you will be redirected to page 1 to see your result, 10 - 16 is on page 2 and so on, but my code still goes to page 1.
function validate() {
var clickHere = document.getElementById("terms");
if(clickHere.checked){
if(counterVal >= 4 || counterVal <=8){
location.replace("/")
}
else{
location.replace("/")
}
}else{
alertify.error('Click the checkbox first.')
}
I need to redirect to another page based on the number of certain moves. For example: if the number of moves after you find all the pairs are between 4 - 8, you will be redirected to page 1 to see your result, 10 - 16 is on page 2 and so on, but my code still goes to page 1.
function validate() {
var clickHere = document.getElementById("terms");
if(clickHere.checked){
if(counterVal >= 4 || counterVal <=8){
location.replace("https://www.w3schools./js/")
}
else{
location.replace("https://javascript.info/")
}
}else{
alertify.error('Click the checkbox first.')
}
Share
Improve this question
edited Dec 29, 2024 at 21:10
philipxy
15.2k6 gold badges43 silver badges97 bronze badges
asked Dec 22, 2021 at 6:06
Vasco WayneVasco Wayne
1051 silver badge7 bronze badges
1
-
try
(clickHere.attr("checked") == true)
in theif()
condition – Mihir Sharma Commented Dec 22, 2021 at 6:21
3 Answers
Reset to default 4if the number of moves after you find all the pairs are between 4 - 8, you will be redirected to page 1 to see your result, 10 - 16 is on page 2 and so on, but my code still goes to page 1
If countVal
is 4 to 8, you want link https://www.w3schools./js/
.
But in the code, that case condition has counterVal >= 4 ||
. The condition will be true if the countVal is more then 8; that is the problem.
if(counterVal >= 4 || counterVal <=8){
Rewrite it like
if(counterVal >= 4 && counterVal <=8){
The simplest way to use JavaScript to redirect to a URL is to set the location property to a new URL using window.location.href
.
The JavaScript code looks like this:
window.location.href = ‘https://ExampleURL./’;
it is a property that tells you what URL is currently being viewed.
Setting a new value, you are telling the browser to load that new URL, similar to what would happen if a user clicked a link.
You function should look like this:
function validate() {
var clickHere = document.getElementById("terms");
if(clickHere.checked){
if(counterVal >= 4 || counterVal <=8){
window.location.href = "https://www.w3schools./js/"
}
else{
window.location.href ="https://javascript.info/"
}
}else{
alertify.error('Click the checkbox first.')
}
The code need to be
if(counterVal >= 4 && counterVal <=8){
window.location.href = "https://www.w3schools./js/1"
}else if(counterVal >= 10 && counterVal <=16){
window.location.href = "https://www.w3schools./js/2"
}else{
location.replace("https://javascript.info/")
}
版权声明:本文标题:alertify - how to redirect to another page when a certain condition is true using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741905895a2404141.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论