javascript - setTimeout with Bootstrap Modal not displaying after time out -


i'm trying delay showing bootstrap modal until 5 seconds have passed. here section of code. seems write have read on mdn. modal not appear after amount of time. 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 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')   } 

use "shown" event handler register timeout on modal , hide it. can chain functions since it's jquery plugin.

$("#mymodal").modal("show").on("shown", function () {     window.settimeout(function () {         $("#mymodal").modal("hide");     }, 5000); }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -