确认后才重定向 [英] Redirect only after confirmation

查看:104
本文介绍了确认后才重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户点击链接,然后弹出一个带有是或否的javascript弹出窗口,但是如果是,则重定向到不同的URL,如果没有,则保持在同一页面上。
我尝试了下面的代码,但是当选择是或否时它会将我带到同一页面。

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>


推荐答案

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

然后

<a href="/mediclaim_portal/logout2.php" onclick="YNconfirm(); return false;">Home</a>

这篇关于确认后才重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆