<--div class="modal fade" id="modalTrilceHome" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="false"> <--script> setTimeout(function() { $('#modalTrilceHome').modal(); }, 5000); <--script> jQuery(document).ready(function($) { $('.cd-popup').addClass('is-visible'); //close popup $('.cd-popup').on('click', function(event) { if ($(event.target).is('.cd-popup-close') || $(event.target).is('.cd-popup')) { event.preventDefault(); $(this).removeClass('is-visible'); } }); //close popup when clicking the esc keyboard button $(document).keyup(function(event) { if (event.which == '27') { $('.cd-popup').removeClass('is-visible'); } }); });