title: onafterprint event only works once
body: <p>I need to carry out my own procedure after calling up the print function of the browser. The problem is that it only runs it once.</p>
  <p>What can I do to make the <code>onafterprint</code> event always run?</p>
  <pre class="lang-js prettyprint-override"><code>window.onafterprint = function() {
    location.href = '{% url 'logout_' %}';
  }
  
  Swal.fire({
    title: 'Example',
    showDenyButton: true,
    showCancelButton: true,
    confirmButtonText: 'Yes',
    confirmButtonColor: 'green',
    denyButtonText: 'No',
    cancelButtonText: 'Cancel'
  }).then((result) =&gt; {
    if (result.isConfirmed) {
      flPrint = true;
    } else if (result.isDenied) {
      flPrint = false;
    }
  
    if ((result.isConfirmed) || (result.isDenied)) {
      $.ajax({
        url: '{% url 'ajax-view' %}',
        dataType: 'json',
        contentType: &quot;application/json&quot;,
        type: 'GET',
        success: function(r) {
          if (r.result) {
            if (flPrint) {
              window.print();
            } else {
              location.href = '{% url 'logout_' %}';
            }
          }
        },
        error: function(err) {
          console.log(err);
        }
      });
    }
  })
  </code></pre>