This script looks like a concise and easy way to get to where you are going.
From what I see, you have to run the script before you delete something, so do not try to stop the request and wait for the user.
For example, when a user clicks a button, you do not delete anything until the confirmation button is checked. This way you make fewer requests (faster load times), and you save yourself some coding.
source share