Javascript confirm dialog

后端 未结 5 862
野性不改
野性不改 2021-02-05 15:59

I want to add a confirm dialog to a delete button to ask the user whether it is ok or not deleting the selected item.

If not, nothing should happend, else a url should be

5条回答
  •  独厮守ぢ
    2021-02-05 16:39

    Better (though far from ideal!): turn it around. Don't let the link do anything, unless you got JavaScript:

    
        Click to delete
    
    

    This at least prevents the link to work without JavaScript. This also reduces the risk of the link accidentally being crawled by Google, or even by some local plugin. (Image if you had a plugin that would try to load/show as thumbnail) the target page on hover of a link!)

    Still, this solution is not ideal. You will actually browse to the url, and the url might show up in the history because of that. You could actually delete Bob, create a new Bob, and then delete that one by accident by just clicking 'back' in the browser!

    A better option would be to use JavaScript or a form to post the desired action. You can make a request to the server with the POST method, or arguably better, the DELETE method. That should also prevent the urls from being indexed.

提交回复
热议问题