0

I need a function, which close the alert box (window) in few seconds automatically:

$("#upload-btn").on('click', function() {
  var dt = canvas.toDataURL('image/jpeg');
  if (window.Lollipop) {
     window.Lollipop.save(dt);
  }
   $.post('saveImage.php',
       {
           img : dt
       }, function(data) {
           if(data){
               alert("Image Saved"); 
           }
       });
  • 1
    Not possible. The only option would be a dialog box ( aka modal ) – Baruch Jun 05 '17 at 21:45
  • 5
    Possible duplicate of [How can I auto hide alert box after it showing it?](https://stackoverflow.com/questions/15466802/how-can-i-auto-hide-alert-box-after-it-showing-it) – Usman Shaukat Jun 05 '17 at 21:46
  • You can try toast notification instead of alert message box. From description of your question toast notification suits your requirement. – Kaushal Jun 05 '17 at 21:47

2 Answers2

3

There is no web api function to close the opened alert.

zerkms
  • 249,484
  • 69
  • 436
  • 539
0

It's NOT possible via standard Web API to close the standard alert box, but you can define your own function or override the alert() function (which is the bad way, better to define own).

const temporaryAlert = function( text, duration ) {
    console.assert(typeof text === "string");
    console.assert(text.length > 0);
    console.assert(typeof duration === "number");

    const item = document.createElement("div");
    item.innerText = text;
    // item.style - add some CSS-stuff to customize the box style
    window.setTimeout(() => item.parentNode.removeChild(item), duration);
    return document.body.appendChild(item);
};