Run extra function when closing modal

Home Forums Porto – Responsive HTML5 Template Run extra function when closing modal

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10005316
    tdyrlund
    Participant

    Hi

    Can you please help me with how to run some extra javascript code when my modal is closed? I’ve tried with:
    <button type="button" class="btn btn-default" id="modalClose" onclick="reloadPage();" data-dismiss="modal">Close</button>

    However reloadPage is never run. The following however works just fine:
    <button type="button" class="btn btn-default" id="modalClose" onclick="alert('Test');" data-dismiss="modal">Close</button>

    My reloadPage function looks like this:

    function reloadPage() {
       alert('test');
    }

    Thanks in advance


    #10005327
    Support
    Keymaster

    Hello, the best way is to use the events:

    (js/custom.js)

    $('#myModal').on('hide.bs.modal', function (event) {
    	alert('test');
    });

    HTML:

    <button class="btn btn-primary btn-lg push-top push-bottom" data-toggle="modal" data-target="#myModal">
    	Launch demo modal
    </button>
    
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    	<div class="modal-dialog">
    		<div class="modal-content">
    			<div class="modal-header">
    				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    				<h4 class="modal-title" id="myModalLabel">Modal title</h4>
    			</div>
    			<div class="modal-body">
    				One fine body...
    			</div>
    			<div class="modal-footer">
    				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    				<button type="button" class="btn btn-primary">Save changes</button>
    			</div>
    		</div>
    	</div>
    </div>

    More information:
    http://getbootstrap.com/javascript/#modals-usage

    Let me know if you need further assistance.

    Kind Regards, Jonas


    #10005344
    tdyrlund
    Participant

    Perfect! Thanks a lot.


Viewing 3 posts - 1 through 3 (of 3 total)

This topic is marked as "RESOLVED" and can not rceive new replies.