Harinder Harinder - 2 months ago 14
Javascript Question

JavaScript uk-modal-close and reload page

Hi i am using http://getuikit.com/docs/modal.html on my site,

my code as below

<a href="#my_modal" class="uk-button" data-uk-modal="">Click to open modal</a>
<div id="my_modal" class="uk-modal">
<div class="uk-modal-dialog">
<a href="" class="uk-modal-close uk-close"></a>
<h1>Title</h1>
<p>...body ...</p>
<div class="uk-modal-footer">
<a href="#" class="uk-button uk-modal-close" id="openmodal">Cancel</a> <!-- Just close the modal -->
<!-- Call external link -->
</div>
</div>
</div>


i want to refresh background when some one click Cancel, i am noob in js but done some research and found

location.reload(true);


this will help in reload page but don't know how can i use it, can any one help

Answer

As per the documentation here, you may use the hide.uk.modal event, which is trigged whenever the modal is closed. In the event handler, you can use the reload functionality. Include jQuery file as well.

$('.modalSelector').on({
    'hide.uk.modal': function(){
       location.reload(true);
    }
});