What is the best way to implement a PopUp when clicking on the delete button instead of redirecting to a new page?

When clicking on the delete button, instead of redirecting to a new page, the best way to implement a PopUp is by using JavaScript to show a confirmation dialog before proceeding with the deletion. This will provide a better user experience by allowing them to confirm their action before deleting the item.

<button onclick="showConfirmation()">Delete</button>

<script>
function showConfirmation() {
    if (confirm("Are you sure you want to delete this item?")) {
        // Proceed with the deletion
        // Add your delete logic here
    } else {
        // Do nothing or cancel the deletion
    }
}
</script>