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.")
}
DOCUMENTATION
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 {
//...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With