I am using a confirm() function for logging out. How can i check whether the user clicked Ok or Cancel. My confirm function is
confirm('Are You Sure')
But now, while clicking both Ok and Cancel the page redirects. How can I resolve it?
I am using a confirm() function for logging out. How can i check whether the user clicked Ok or Cancel. My confirm function is
confirm('Are You Sure')
But now, while clicking both Ok and Cancel the page redirects. How can I resolve it?
if (confirm('Are You Sure?')){
window.location = "http://www.google.com/";
}else{
alert("You are not redirected.")
}
You need to get the return value of confirm
, and then decide what to do next.
var answer = confirm('Are You Sure');
if (answer) {
//...
} else {
//...
}
I experimented with visual studio and on my computer works two ways:
if (confirm("Do you want to log out?")) {
//..
}
else {
//..
}
Or:
var question = confirm("Do you want to log out?");
if (question == true) {
//..
}
else {
//..
}