Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect only after confirmation

Tags:

javascript

php

I want to have the user click on a link then have a javascript pop-up with a yes or no choice,but if yes redirect to different url if no, then stay on the same page. I tried the code below but it takes me to the same page when selecting yes or no.

function YNconfirm() { 
 if (window.confirm('Really go to another page?'))
{
    alert("You agree") 
window.location.href = (http:///mediclaim_portal/logout2.php');
}
else
{
window.location.href = (this.document);
}};
</script>

then 
<a href="\mediclaim_portal/logout2.php" onclick="YNconfirm()">Home</a>
like image 453
Mark Avatar asked Feb 27 '26 21:02

Mark


1 Answers

function YNconfirm() { 
 if (window.confirm('Really go to another page?'))
 {
   alert("You agree") 
   window.location.href = 'http:///mediclaim_portal/logout2.php';
 }
}

then

<a href="/mediclaim_portal/logout2.php" onclick="YNconfirm(); return false;">Home</a>
like image 120
Paul Roub Avatar answered Mar 01 '26 10:03

Paul Roub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!