Image

Better Alert

I redefined the alert function to make it easier to manage multiple alerts in succession. It passes its argument on to the confirm function, and if "cancel" is clicked, alerts are quelled for three seconds, or however long you specify.


alert.delay = 3000;
// 3 seconds should be enough time to tame all the runaway alerts.
// If not, it's definitely enough time to close the browser window.

function alert(message)
{
  // if alerts are not being blocked...
  if (!alert.block)
  {
    // ...issue the alert as a confirm.
    // If cancel is clicked, alert.block will be true,
    // and the other two conditions will be tested.
    // If there's a delay set, and no timeout in progress
    // already, set a timeout for unblocking alerts.
    
    if ((alert.block = !confirm(message)) /*** assignment ***/
        && alert.delay > 0 && !alert.timeout)
    {
      alert.timeout = setTimeout("alert.unblock();",alert.delay);
    }
  }
}

alert.unblock = function()
{
  alert.block = false;
  alert.timeout = null; // keep things in synch
};


Or, a "compressed" version (much smaller file size and does the same thing, but also harder for a human to read):

alert.delay = 3000;

function alert(a){if(!alert.block){if((alert.block=!confirm(a))&&alert.delay>
0&&!alert.timeout){alert.timeout=setTimeout("alert.unblock();",alert.delay);}
}}alert.unblock=function(){alert.block=false;alert.timeout=null;};



Sorry about deleting it the first time... As usual, I noticed a bug right after I posted.