This would be wrong approach. See also the reasonable comment to the question by F-ES Sitecore.
JavaScript
alert
call is blocking. If you want to bypass it, call it conditionally, so you would either perform the call or not. For showing some content for few second, use the timer and some HTML element on the same page. You can temporarily disable all controls of the current
document.body
, show some element with the information you wanted to present using
alert
, wait few seconds of time and then remove this element from the DOM tree. You can even perform the
dimming: cover all the area of the current window with some element with absolute positioning and set its
opacity
level to some value between 0 and 1. Don't forget to handle the
window.resize
, to adjust size/position of your two elements, the "dimmer" element and your message element.
This feature is quite easy to develop, but I'm sure you will be able to find some available implementation.
[EDIT]
Recently, after I already answered this question, I published an article on the topic. Please see:
Modal Popup From Scratch[
^].
[END EDIT]
But I have a much better suggestion: change your UI design. Most users will be highly irritated when something disappears without their consent. What you may need is the usual "modal popup" which is removed by the user click, not by timer, such as one implemented as a jQuery UI Dialog Wizard:
https://jqueryui.com/dialog[
^].
There are many 3-rd party plug-ins collectively known as "modal popup" control elements; they feature many different visual effects, including dimming.
Moreover, I would advise you to re-thing even the idea of showing an alert. Even though there are many cases when it is really important, there are many arguments against them, and many alternatives. I don't mean not using such things, I mean using them with care, only in some very special cases. Most people dislike when something interrupts their workflow. I don't know your exact situation, so you decide.
Also note that JavaScript functions like
alert
,
confirm
and
prompt
are hardly acceptable for real production versions of Web applications. They are too inflexible and ugly. Well,
alert
can be useful during development or, at best, for showing exception information, and only in the cases when it propagates to your piece of code due to some unfixed bugs.
—SA