简体   繁体   中英

Confirmation on href link

I have a href and confirmation on the click of that 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.

If it is not possible, is there any other way to achieve this? My href page is php page.

You can use onbeforeunload to prevent user leaving the page without confirmation:

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.

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;

        }

    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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