Automatic modal closure after button pressed on it

Can you try this one

<script>
window.addEventListener('load', function() {
    setTimeout(function() {
        var e = document.getElementsByClassName("sw-modal-close")[0];
        e.setAttribute('onclick', "MicroModal.close('sw-modal');  location.reload();");
    }, 1600);
});
</script>

To be inserted in the footer code of the page settings (in the page where the modal is open when you click on a list item). When closing the modal with the close button, it should reload the page.