Question

I have my twitter BootBox open like this:

bootbox.dialog("{{$steps[0]}}"); 

after ten Seconds, I close my BootBox like this:

window.setTimeout(function(){
    bootbox.hideAll();
}, 10000);

Is it possible to show the remaining seconds until close in the BootBox?

Was it helpful?

Solution

You can add a div to your message, like this:

bootbox.dialog("Your message <div id='SecondsRemaining'>10</div>"); 

Then update it using this function:

(function(){
    var remaining = 10; // Number of seconds
    var obj = document.getElementById("SecondsRemaining");
    var timeout = window.setInterval(function(){
        remaining--;
        if(remaining==0) {
            // Time is up, stop the timer and hide the bootbox
            window.clearInterval(timeout);
            bootbox.hideAll();
            return;
        }
        obj.innerHTML = remaining; // Update the value displayed
    }, 1000); // Decrease counter every second
})();

For bootbox 4+ the format has changed. The dialog should be created:

bootbox.dialog({ message: "Your message <div id='SecondsRemaining'>10</div>" }); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top