By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,600 Members | 1,887 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,600 IT Pros & Developers. It's quick & easy.

alert() and message window

P: n/a
Is there a way to create an alert-like message box that uses a custom
image? Basically, I want to replace the default ! image with something else.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 20 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Justin Koivisto <sp**@koivi.com> writes:
Is there a way to create an alert-like message box that uses a custom
image? Basically, I want to replace the default ! image with something
else.


No, not in general.
Some browsers might have extensions that allow that, but there is no
method in standard javasript to change the looks of the alert dialog.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
@SM
Justin Koivisto a ecrit :
Is there a way to create an alert-like message box that uses a custom
image? Basically, I want to replace the default ! image with something else.
alert('balbla')
popup a standard window
yon can't change it

you can only do open a new html window

<script type="text/javascript"><!--
var truc=false;
debut='<html><head><title>Alert</title>\n<style type="text/css">\n';
debut+='body{background:lightyellow;font-family:arial;color:maroon;';
debut+='font-size:12px;}\nh1{text-align;center;font-size:16px;color:red;}';
debut+='\n</style>\n</head>\n<body>\n<h1>';
fin='\n<p><hr>\n<p><form><p style="text-align:right;margin-right:40px;">';
fin += '<input type=button value="OK" onclick="self.close();">\n</form></html>';

function alarme(title,text) {
if(truc!=false || !truc.closed) {truc.close(); truc=false;}
truc=window.open('','','width=300,height=200,resiz able=0');
truc.document.open();
truc.document.write(debut+title+'</h1>\n'+text+fin);
truc.document.close();
}
// --></script>

<a href="javascript:alarme('Attention !','This is my message :<br>nothing to tell');"see alarme</a>


--
************************************************** ************
Stéphane MORIAUX : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanemoriaux/internet/
************************************************** ************
Jul 20 '05 #3

P: n/a
@SM wrote:
Justin Koivisto a ecrit :

Is there a way to create an alert-like message box that uses a custom
image? Basically, I want to replace the default ! image with something else.

alert('balbla')
popup a standard window
yon can't change it

you can only do open a new html window

<script type="text/javascript"><!--
var truc=false;
debut='<html><head><title>Alert</title>\n<style type="text/css">\n';
debut+='body{background:lightyellow;font-family:arial;color:maroon;';
debut+='font-size:12px;}\nh1{text-align;center;font-size:16px;color:red;}';
debut+='\n</style>\n</head>\n<body>\n<h1>';
fin='\n<p><hr>\n<p><form><p style="text-align:right;margin-right:40px;">';
fin += '<input type=button value="OK" onclick="self.close();">\n</form></html>';

function alarme(title,text) {
if(truc!=false || !truc.closed) {truc.close(); truc=false;}
truc=window.open('','','width=300,height=200,resiz able=0');
truc.document.open();
truc.document.write(debut+title+'</h1>\n'+text+fin);
truc.document.close();
}
// --></script>

<a href="javascript:alarme('Attention !','This is my message :<br>nothing to tell');"
see alarme</a>


Thanks, I guess I'll just have to with a new window rather than an alert.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 20 '05 #4

P: n/a

"Justin Koivisto" <sp**@koivi.com> wrote in message
news:BE*****************@news7.onvoy.net...
@SM wrote:
Justin Koivisto a ecrit :

Is there a way to create an alert-like message box that uses a custom
image? Basically, I want to replace the default ! image with something
else.

alert('balbla')
popup a standard window
yon can't change it

you can only do open a new html window

<script type="text/javascript"><!--
var truc=false;
debut='<html><head><title>Alert</title>\n<style type="text/css">\n';
debut+='body{background:lightyellow;font-family:arial;color:maroon;';
debut+='font-size:12px;}\nh1{text-align;center;font-size:16px;color:red;}'; debut+='\n</style>\n</head>\n<body>\n<h1>';
fin='\n<p><hr>\n<p><form><p style="text-align:right;margin-right:40px;">'; fin += '<input type=button value="OK" onclick="self.close();">\n</form></html>';
function alarme(title,text) {
if(truc!=false || !truc.closed) {truc.close(); truc=false;}
truc=window.open('','','width=300,height=200,resiz able=0');
truc.document.open();
truc.document.write(debut+title+'</h1>\n'+text+fin);
truc.document.close();
}
// --></script>

<a href="javascript:alarme('Attention !','This is my message :<br>nothing to tell');"
see alarme</a>


Thanks, I guess I'll just have to with a new window rather than an alert.

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.


Yeah, but be careful... Popup blockers will try to stop you from doing
this...

Brian
Jul 20 '05 #5

P: n/a
Brian wrote:
"Justin Koivisto" <sp**@koivi.com> wrote in message
news:BE*****************@news7.onvoy.net...
@SM wrote:
Justin Koivisto a ecrit :

Is there a way to create an alert-like message box that uses a custom
image? Basically, I want to replace the default ! image with something
<snip>
you can only do open a new html window
<snip>
if(truc!=false || !truc.closed) {truc.close(); truc=false;}

This should have read:
if(truc!=false && !truc.closed) {truc.close(); truc=false;}
Thanks, I guess I'll just have to with a new window rather than an alert.


Yeah, but be careful... Popup blockers will try to stop you from doing
this...


That's OK, it's just help tips inside a custom CMS, so it's no big deal
if they get blocked. Afterall, that's what the system's documentation is
for anyway. ;)

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 20 '05 #6

P: n/a
@SM
Justin Koivisto a ecrit :
Brian wrote:
"Justin Koivisto" <sp**@koivi.com> wrote in message
news:BE*****************@news7.onvoy.net...
@SM wrote:
if(truc!=false || !truc.closed) {truc.close(); truc=false;}
This should have read:
if(truc!=false && !truc.closed) {truc.close(); truc=false;}
In my mind ==> not at all !
If truc has become true or anything else by innadvertance
or
if the pop-up is allready open (if it is not closed)
close the popup
before re-open (and like that its size may be changed)

Thanks, I guess I'll just have to with a new window rather than an alert.
Yeah, but be careful... Popup blockers will try to stop you from doing
this...


tant pis pour ceux là !
They have to choose a clever blocker ! tremendous !
That's OK, it's just help tips inside a custom CMS, so it's no big deal
if they get blocked. Afterall, that's what the system's documentation is
for anyway. ;)

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.


--
************************************************** ************
Stéphane MORIAUX : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephanemoriaux/internet/
************************************************** ************
Jul 20 '05 #7

P: n/a
@SM wrote:
Justin Koivisto a ecrit :
Brian wrote:
> "Justin Koivisto" <sp**@koivi.com> wrote in message
> news:BE*****************@news7.onvoy.net...
>
>>@SM wrote:
>>>if(truc!=false || !truc.closed) {truc.close(); truc=false;}
This should have read:
if(truc!=false && !truc.closed) {truc.close(); truc=false;}


In my mind ==> not at all !
If truc has become true or anything else by innadvertance
or
if the pop-up is allready open (if it is not closed)
close the popup
before re-open (and like that its size may be changed)


What the heck are the both of you talking about? `truc' is the result
of `window.open(...)' after all, so it either references a Window object
or its value is `null'.

Thus the above should read:

if (truc && !truc.closed) truc.close();

so that `!truc.closed' is only evaluated if `truc' is evaluated to
`true'. Otherwise `truc.closed' will trigger a script error, before
the negation operator can do its work; so Stéphane, your script *is*
flawed and Justin is right, however the type of the operands was
still suboptimal, forcing conversion. The following

truc = false;

assignment can be obviously omitted, since it is overwritten by
the next statement anyway:

truc = window.open('', '', 'width=300,height=200,resizable=0');

But I would never do it that way since in flawed implementations
closing and opening windows eats system resources without freeing
them when they are not longer used. Instead I would write:

var truc = null;

function alarme(title, text)
{
if (!(truc && !truc.closed))
truc = window.open('', '', 'width=300,height=200,resizable=0');
if (truc)
{
truc.document.open();
truc.document.write(debut + title + '<\/h1>\n' + text + fin);
truc.document.close();
}
}
--


The trailing space is still missing from
what can become a signature separator.
PointedEars
Jul 20 '05 #8

P: n/a
@SM
Thomas 'PointedEars' Lahn a ecrit :
@SM wrote:
Justin Koivisto a ecrit :
Brian wrote:
> "Justin Koivisto" <sp**@koivi.com> wrote in message
> news:BE*****************@news7.onvoy.net...
>
>>@SM wrote:
>>>if(truc!=false || !truc.closed) {truc.close(); truc=false;}

This should have read:
if(truc!=false && !truc.closed) {truc.close(); truc=false;}
In my mind ==> not at all !
If truc has become true or anything else by innadvertance
or
if the pop-up is allready open (if it is not closed)
close the popup
before re-open (and like that its size may be changed)


What the heck are the both of you talking about? `truc' is the result
of `window.open(...)' after all, so it either references a Window object
or its value is `null'.


I absolutly agree all what you say,
However you never know what a newbie can do ;-))
Thus the above should read:

if (truc && !truc.closed) truc.close();
And if the guy din't 1st declare this 'truc'
IE will cry once more again ! -;))
So, even if truc is closed, I tell to him 'truc' is false
hammer on nail don't cost too much ;-))
truc = false;

assignment can be obviously omitted, since it is overwritten by
the next statement anyway:
???? tell it to IE
If truc isn't declared and not launched before
with
if(truc && || blabla)
IE will not accept it ! " Truc unknown ! Error Error Error ! "
It is so unclever that you have to tell it
if truc unknown
to be quiet.
But you turned the problem with your code below.

if( not wrong )
But I would never do it that way since in flawed implementations
closing and opening windows eats system resources without freeing
them when they are not longer used. Instead I would write:
I don't understand the real difference [ if(truc) ]
By the fact if a window is opened, it would be to use it, no?
Do you mean if the popup is closed, system ressources for a new popup
are still running ?
I suppose that the complete JS code is running in system all long
the page is not closed (unloaded).
var truc = null;

function alarme(title, text)
{
if (!(truc && !truc.closed))
truc = window.open('', '', 'width=300,height=200,resizable=0');
if (truc)
{
truc.document.open();
truc.document.write(debut + title + '<\/h1>\n' + text + fin);
truc.document.close();
}
}
--
The trailing space is still missing from
what can become a signature separator.


Oh ! of course ! I'll try to think it
PointedEars


--
******************
Stéphane MORIAUX

Jul 20 '05 #9

P: n/a
@SM wrote:
Thomas 'PointedEars' Lahn a ecrit :
What the heck are the both of you talking about? `truc' is the result
of `window.open(...)' after all, so it either references a Window object
or its value is `null'.
I absolutly agree all what you say,
However you never know what a newbie can do ;-))


Maybe they should learn how to write working code? Experience shows
that you can never completely avoid problems by technical means that
have social causes.
Thus the above should read:

if (truc && !truc.closed) truc.close();


And if the guy din't 1st declare this 'truc'
IE will cry once more again ! -;))
So, even if truc is closed, I tell to him 'truc' is false
hammer on nail don't cost too much ;-))


So they should declare it. Simple as that.

If you want *almost* 100% security, you could write

if (!(typeof truc != "undefined" && !truc.closed
&& (typeof truc.close == "function"
|| typeif truc.close == "object")))
{
truc.close();
}

But that fails below JavaScript 1.1 (because of the `typeof' operator)
and even if the wrong identifier is used. With JavaScript 1.0 one
could still use a property of a user-defined object and test it for
existence but it will also fail if worng identifiers are used or the
object was not/improperly defined. See above.
truc = false;

assignment can be obviously omitted, since it is overwritten by
the next statement anyway:


????


Your `?' key is borken.
tell it to IE
Not only that particular UA will show an error then. Mozilla/3.0+
for example, will always show it in its JavaScript console
(`javascript:' URI; Tools, Web Development, JavaScript Console or
like that) and Opera 6+ will IIRC automagically show the JavaScript
console window if enabled, otherwise errors are logged in the
background (as Mozilla also does).
But I would never do it that way since in flawed implementations
closing and opening windows eats system resources without freeing
them when they are not longer used. Instead I would write:


I don't understand the real difference [ if(truc) ]
By the fact if a window is opened, it would be to use it, no?


Not necessary. We do not have modal windows here which shows, as
I realized later, another problem with user-defined message windows.
See below.
Do you mean if the popup is closed, system ressources for a new popup
are still running ?
Yep.
I suppose that the complete JS code is running in system
all long the page is not closed (unloaded).


AIUI, it is not. Once the J(ava)Script engine has finished
compiling the code and interpreting the resulting bytecode
with the JSVM, control is returned to the UA. However, the
J(ava)Script engine or the JSVM, needs to maintain memory
where to store globals and pointers to them.

But it is not a matter of the running JavaScript code but
of the allocated system resources not properly freed because
of bad implementation(s) of and/or in the API, i.e. keeping
memory allocated for objects that are no longer in use and not
reallocating it (completely) when creation of objects requires
it. Microsoft Office applications are a sparkling example of
that at least on Windows 95 based systems. (Alas, current
Mozilla/5.0 for 32 bit Windows is apparently another.
Sigh. [psf 10.1])
var truc = null;

function alarme(title, text)
{
if (!(truc && !truc.closed))
truc = window.open('', '', 'width=300,height=200,resizable=0');
if (truc)
{
truc.document.open();
truc.document.write(debut + title + '<\/h1>\n' + text + fin);
truc.document.close();
}
}
Another problem is that the "alert" window is not automagically on
top if already open. For this should be like an alert(...) message
and therefore should be on top when possible and also dependent to
the window it opened by (so that it is closed when the "parent"
window is closed), one could use

var truc = null;

function alarme(title, text)
{
if (!(truc && !truc.closed))
truc =
window.open(
'',
'',
'width=300,height=200,resizable=yes,dependent=yes' );
if (truc)
{
truc.document.open("text/html");

// BTW: I would rather use a default (and valid) HTML
// structure and only put in the var.s, assigning it
// to a string later to be written.
truc.document.write(debut + title + '<\/h1>\n' + text + fin);

truc.document.close();

if (typeof truc.focus == "function"
|| typeof truc.focus == "object")
{
truc.focus();
}
}
}

(`dependent' is a feature AFAIK implemented n Netscape 4.x and
Mozilla/5.0 only, IE and others will/shoul safely ignore it.)

However, I heard of implementations (namely AOL's IE version) where
there is either no `focus' method or it does not work as expected.

Now we face more a problem of philosophy: What is better? Possibly
eating up system resources with bad implementations by closing and
reopening windows while possibly ensuring that error messages are
displayed, or possibly not having the error message displayed on top
in any case but possibly preserving system resources?

I would then argue in general that the error message is not that
important than enough free system resources because the former only
affects the so-called Web application while the latter affects the
whole system and all running applications.

But I doubt you have to make that choice here. Users are used to
default alert(...) messages, you can also use confirm(...) and even
prompt(...) which they are also used to, and if even that does not
suffice, last but not least a solution without JavaScript will still
do the trick and will do it more reliably than the previously
mentioned ones with it.
> --


The trailing space is still missing from
what can become a signature separator.


Oh ! of course ! I'll try to think it


If it is correct while you are writing your postings/mails, do not
use the HTML editor of Netscape 4.x for postings/mails and that known
problem will disappear for you :)
PointedEars
Jul 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.