okjfokjrf
okjfokjrf

Reputation: 135

Close toastr.error after a few seconds in Javascript

I'm using toastr.error('Testing pop-up') in Javascript to show me a pop-up when there is an error in the application, but I can't see in the official documentation how to close this pop-up after X seconds automatically without pressing any button. Does anyone know how?

Upvotes: 0

Views: 1172

Answers (2)

Meligy
Meligy

Reputation: 36594

The signature for the error function is:

            function error(message, title, optionsOverride) {

https://github.com/CodeSeven/toastr/blob/50092cc604850a16c985520b63df184d3e0b4086/toastr.js#L46

You can pass options to hide it as needed.

You can play with the options to see the best fit in the demo page:

https://codeseven.github.io/toastr/demo.html

enter image description here

Upvotes: 1

Simone Rossaini
Simone Rossaini

Reputation: 8162

You can set timeout like:

Timeouts
Control how toastr interacts with users by setting timeouts appropriately.

toastr.options.timeOut = 30; // How long the toast will display without user interaction
toastr.options.extendedTimeOut = 60; // How long the toast will display after a user hovers over it

Reference:

Upvotes: 1

Related Questions