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
Post a Comment