473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

alert() and message window

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
9 4963
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
@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
@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

"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
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
@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
@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
@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
@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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert Oschler | last post by:
If I set window.onerror to an error handler I've created, I don't see the browser error dialogs anymore but I don't see the alert() messages in my error handler pop up either. Can someone tell me...
2
by: Robert Nurse | last post by:
Hi All, I've got a strange problem in IE that I wonder if anyone has seen before. Basically, I've got a two window scenario. The parent window opens the child via window.open(). The child...
11
by: Alistair Saldanha | last post by:
I'm looking for the event that is fired by Internet Explorer to an "alert": <SCRIPT> Alert("You already have a session open") </SCRIPT> The event would be webBrowser.Document.???? Much...
1
by: buran | last post by:
Dear ASP.NET Programmers, I am developing an intranet application using ASP.NET. I want to add such a functionality that the application displays a pop-up box to confirm when the user tries to...
6
by: taras.di | last post by:
Hi everyone, I've just spent the last 2 hours banging me head against the desk trying to figure this one out. I eventually figured out that sometimes a form doesn't exist for the popup I'm...
3
by: umdsasha | last post by:
So, basically, I need to detect whether an alert window was thrown. I can't find where it's thrown from but I need to disable a button only if there were no alert windows thrown. Any ideas? ...
3
by: gouthami | last post by:
I have a tree Node in my application and i have set the following code in the NavigateUrl property of the tree node. Please see my code below (which is present in my 'code behind' c# file). My...
9
by: Tonio Tanzi | last post by:
I have an asp page with this tag <body onLoad="show_msg('<%=error_msg%>');"> where "show_msg" is a javascript function that shows the message contained in the asp variable "error_msg" only if...
24
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.