I have an extension with a backend view where I have a button which routes to another url. When the user clicks the button I want to show a pop up which asks him a second time if he/she really wants to continue. I have the following code in my template:

<button class="action-third" type="submit" title="Reset" id="reset-all" onclick="setLocation('<?php echo $block->getUrl('some/url/reset') ?>')">
    <span>Reset all</span>
<script type="text/javascript">// <![CDATA[
    ], function($, confirmation) {
        $('#reset-all').on('click', 'button.action-third', function(event){
                title: 'Reset...',
                content: 'Do you really want to reset?',
                actions: {
                    confirm: function(){},
                    cancel: function(){},
                    always: function(){}
    // ]]></script>

But that does not work. Here are my two questions:

  • What do I have to do so that the pop up shows up?
  • What should I insert in the confirm() and cancel() function so that if the user clicks OK, he gets to the route the button links to, otherwise not.
  • how did you done this
    – Jaisa
    Mar 7 '19 at 9:17

If you are in adminhtml area then you can use confirmSetLocation() function in javascript like this:

var url = '<?php echo $block->getUrl('some/url/reset') ?>';
$('#reset-all').on('click', 'button.action-third', function(event){
    confirmSetLocation('Do you really want to reset?', url);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.