[Javascript] A Temporary Alert?

David Lovering dlovering at gazos.com
Sun Dec 23 07:58:54 CST 2007


This is hardly the most elegant solution, but it works on most browser 
platforms I've dealt with.

In the HTML body declaration of your dialog, create an 'onload' event 
handler of the following sort:

onload = "setTimeout( 'window.this.close()', 5000)";

This is dirt simple, and no doubt will call down the wrath of the Javascript 
gurus with much more refined (and less fragile) solutions.

While you can reference an alert as a window and play the same games, it is 
often hard (and somewhat browser dependent) to do so; I prefer to create a 
child window and use it instead of a generic alert.  With a little 
imagination, you can manipulate the window parameters so that the user is 
completely unaware that he is not talking directly to an alert - but you 
have the window id and name under your full control.  It also is less 
complicated to reference the <body> portion of the code in order to insert 
the onload handler.

-- Dave Lovering




----- Original Message ----- 
From: "tedd" <tedd at sperling.com>
To: "JavaScript List" <javascript at lists.evolt.org>
Sent: Saturday, December 22, 2007 3:33 PM
Subject: [Javascript] A Temporary Alert?


> Hi gang:
>
> I've looked, but can not find a temporary Alert.
>
> What I mean is:
>
> "Hi, this is a temporary Alert box and I will automatically close in
> 5 seconds."
>
> An Alert that will notify the user of something, but will NOT require
> the user to respond to go away. But instead, will close on its own
> after a set time.
>
> It sounds simple enough, but I couldn't find nor generate one. Can
> this be done?
>
> Thanks in advance for any references or code.
>
> Cheers,
>
> tedd
>
> -- 
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
> 





More information about the Javascript mailing list