Confirm Alert

  • 3 years-4 months

    Confirm Alert

    • Category : jquery
    • Viewed : 78 times
    • Posted On :
    • Posted by : Guley

    add confirmation alert before your link active

    <script>
    function confirmDelete(delUrl) {
      if (confirm("Are you sure you want to delete")) {
        document.location = delUrl;
      }
    }
    </script>
    
    <a href="javascript:confirmDelete('delete.page?id=1')">Delete</a>
    
    or
    
    <a href="delete.page?id=1" onclick="return confirm('Are you sure you want to delete?')">Delete</a>
    
    or
    use this cdn's in your header
    
    https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.css
    https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.js
    
    
    <a href="delete.page?id=1" class="confirmation">Delete</a>
    
    jQuery('.confirmation').click(function (e) {
        var href = jQuery(this).attr('href');
    
        swal({
            title: "Are you sure?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes",
            cancelButtonText: "No",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        window.location.href = href;
                    }
                });
    
        return false;
    });
    

Report this or Ask your own question

Your Answer

When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.