简体   繁体   English

在href链接上进行确认

[英]Confirmation on href link

I have a href and confirmation on the click of that href. 我有一个href和对该点击的确认。

 <a href="stackoverflow.com" onclick="return confirm('Sure?')">Go to SO</a> 

But I want confirmation from the user if they hit the href link directly by typing the URL. 但是我想从用户确认他们是否通过键入URL直接单击href链接。

If it is not possible, is there any other way to achieve this? 如果不可能,还有其他方法可以实现吗? My href page is php page. 我的href页面是php页面。

You can use onbeforeunload to prevent user leaving the page without confirmation: 您可以使用onbeforeunload来防止用户未经确认就离开页面:

window.onbeforeunload = function(){
  return 'Sure?';
};

您将必须创建一个专门用于重定向用户的页面,例如,可以使用id和链接将链接存储在数据库中,然后仅将用户链接到yourlink?id=<yourid> ,然后在这一页 :)

What you'll want to do is put the confirmation on the actual page (if you are the owner). 您需要做的是在实际页面上输入确认信息(如果您是所有者)。 Make sure to put this in the <head> section so that it won't show anything on the page before it asks the user. 确保将其放在<head>部分中,这样它在询问用户之前不会在页面上显示任何内容。

Like: 喜欢:

<script type="text/javascript">
if(!confirm('Are you sure?')) {
    location.href = 'some page to redirect to on cancel';
}
</script>
<a class="tip deleteuser" data-original-title="Delete" href="<?php echo $site_path['admin_url']; ?>user/delete/<?php echo $allUSers[$i]['id'];?>"><i class="fa fa-trash-o fa-1x"></i></a>&nbsp;


$('.deleteuser').click(function () {

        var confirmation = confirm("Are you sure that you want to delete this user ?");

        if (confirmation) {

            return true;

        } else {

            return false;

        }

    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM