Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
23
rated 0 times [  24] [ 1]  / answers: 1 / hits: 21914  / 11 Years ago, sun, may 12, 2013, 12:00:00

I'm trying to delay showing a Bootstrap modal until 5 seconds have passed. Here is the section of my code. It seems write from what I have read on MDN. The modal does not appear after any amount of time. Any help would be appreciated.



var timeout;
function modalAlert(message){
$(#myModalLabel).text(Hey Look!)
$('.modal-body').html(<img src='+message+'>);
timeout = window.setTimeout(showModal,5000);

}
function showModal(){
console.log(HERE)
$(#myModal).modal('show')
}


Vijay Ramamurthy helped me find the solution:



var timeout;
function modalAlert(message){
$(#myModalLabel).text(Hey Look!)
$('.modal-body').html(<img src='+message+'>);
window.setTimeout(function(){showModal();},5000);

}
function showModal(){
console.log(HERE)
$(#myModal).modal('show')
}

More From » jquery

 Answers
4

Use the shown event handler to register a timeout on the modal and then hide it. You can chain the functions together since it's a jQuery plugin.



$(#myModal).modal(show).on(shown, function () {
window.setTimeout(function () {
$(#myModal).modal(hide);
}, 5000);
});

[#78273] Friday, May 10, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brandensebastiand

Total Points: 323
Total Questions: 115
Total Answers: 106

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;