user8103277
user8103277

Reputation:

javascript alert box close automatically

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"); 
           }
       });

Upvotes: 0

Views: 2383

Answers (2)

user4959035
user4959035

Reputation:

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);
};

Upvotes: 0

zerkms
zerkms

Reputation: 254886

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

Upvotes: 3

Related Questions