alert() and message window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin Koivisto

    #1

    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 - spam@koivi.com
    PHP POSTERS: Please use comp.lang.php for PHP related questions,
    alt.php* groups are not recommended.

  • Lasse Reichstein Nielsen

    #2
    Re: alert() and message window

    Justin Koivisto <spam@koivi.com > writes:
    [color=blue]
    > 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.[/color]

    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 - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • @SM

      #3
      Re: alert() and message window

      Justin Koivisto a ecrit :
      [color=blue]
      > 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.[/color]

      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><h ead><title>Aler t</title>\n<style type="text/css">\n';
      debut+='body{ba ckground:lighty ellow;font-family:arial;co lor:maroon;';
      debut+='font-size:12px;}\nh1 {text-align;center;fo nt-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;mar gin-right:40px;">';
      fin += '<input type=button value="OK" onclick="self.c lose();">\n</form></html>';

      function alarme(title,te xt) {
      if(truc!=false || !truc.closed) {truc.close(); truc=false;}
      truc=window.ope n('','','width= 300,height=200, resizable=0');
      truc.document.o pen();
      truc.document.w rite(debut+titl e+'</h1>\n'+text+fin );
      truc.document.c lose();
      }
      // --></script>

      <a href="javascrip t:alarme('Atten tion !','This is my message :<br>nothing to tell');"[color=blue]
      >see alarme</a>[/color]

      --
      *************** *************** *************** *************** **
      Stéphane MORIAUX : mailto:stephane OTER-MOImoriaux@wana doo.fr
      Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)

      *************** *************** *************** *************** **


      Comment

      • Justin Koivisto

        #4
        Re: alert() and message window

        @SM wrote:
        [color=blue]
        > Justin Koivisto a ecrit :
        >
        >[color=green]
        >>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.[/color]
        >
        >
        > 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><h ead><title>Aler t</title>\n<style type="text/css">\n';
        > debut+='body{ba ckground:lighty ellow;font-family:arial;co lor:maroon;';
        > debut+='font-size:12px;}\nh1 {text-align;center;fo nt-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;mar gin-right:40px;">';
        > fin += '<input type=button value="OK" onclick="self.c lose();">\n</form></html>';
        >
        > function alarme(title,te xt) {
        > if(truc!=false || !truc.closed) {truc.close(); truc=false;}
        > truc=window.ope n('','','width= 300,height=200, resizable=0');
        > truc.document.o pen();
        > truc.document.w rite(debut+titl e+'</h1>\n'+text+fin );
        > truc.document.c lose();
        > }
        > // --></script>
        >
        > <a href="javascrip t:alarme('Atten tion !','This is my message :<br>nothing to tell');"
        >[color=green]
        >>see alarme</a>[/color][/color]

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

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

        Comment

        • Brian

          #5
          Re: alert() and message window


          "Justin Koivisto" <spam@koivi.com > wrote in message
          news:BE%Bb.1657 $Uz.54556@news7 .onvoy.net...[color=blue]
          > @SM wrote:
          >[color=green]
          > > Justin Koivisto a ecrit :
          > >
          > >[color=darkred]
          > >>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[/color][/color][/color]
          else.[color=blue][color=green]
          > >
          > >
          > > 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><h ead><title>Aler t</title>\n<style type="text/css">\n';
          > > debut+='body{ba ckground:lighty ellow;font-family:arial;co lor:maroon;';
          > >[/color][/color]
          debut+='font-size:12px;}\nh1 {text-align;center;fo nt-size:16px;color :red;}';[color=blue][color=green]
          > > debut+='\n</style>\n</head>\n<body>\n <h1>';
          > > fin='\n<p><hr>\ n<p><form><p[/color][/color]
          style="text-align:right;mar gin-right:40px;">';[color=blue][color=green]
          > > fin += '<input type=button value="OK"[/color][/color]
          onclick="self.c lose();">\n</form></html>';[color=blue][color=green]
          > >
          > > function alarme(title,te xt) {
          > > if(truc!=false || !truc.closed) {truc.close(); truc=false;}
          > > truc=window.ope n('','','width= 300,height=200, resizable=0');
          > > truc.document.o pen();
          > > truc.document.w rite(debut+titl e+'</h1>\n'+text+fin );
          > > truc.document.c lose();
          > > }
          > > // --></script>
          > >
          > > <a href="javascrip t:alarme('Atten tion !','This is my message[/color][/color]
          :<br>nothing to tell');"[color=blue][color=green]
          > >[color=darkred]
          > >>see alarme</a>[/color][/color]
          >
          > Thanks, I guess I'll just have to with a new window rather than an alert.
          >
          > --
          > Justin Koivisto - spam@koivi.com
          > PHP POSTERS: Please use comp.lang.php for PHP related questions,
          > alt.php* groups are not recommended.
          >[/color]

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

          Brian


          Comment

          • Justin Koivisto

            #6
            Re: alert() and message window

            Brian wrote:
            [color=blue]
            > "Justin Koivisto" <spam@koivi.com > wrote in message
            > news:BE%Bb.1657 $Uz.54556@news7 .onvoy.net...
            >[color=green]
            >>@SM wrote:
            >>[color=darkred]
            >>>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[/color][/color][/color]

            <snip>
            [color=blue][color=green][color=darkred]
            >>>you can only do open a new html window[/color][/color][/color]

            <snip>
            [color=blue][color=green][color=darkred]
            >>>if(truc!=fal se || !truc.closed) {truc.close(); truc=false;}[/color][/color][/color]

            This should have read:
            if(truc!=false && !truc.closed) {truc.close(); truc=false;}
            [color=blue][color=green]
            >>Thanks, I guess I'll just have to with a new window rather than an alert.[/color]
            >
            > Yeah, but be careful... Popup blockers will try to stop you from doing
            > this...[/color]

            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 - spam@koivi.com
            PHP POSTERS: Please use comp.lang.php for PHP related questions,
            alt.php* groups are not recommended.

            Comment

            • @SM

              #7
              Re: alert() and message window

              Justin Koivisto a ecrit :
              [color=blue]
              > Brian wrote:
              >[color=green]
              > > "Justin Koivisto" <spam@koivi.com > wrote in message
              > > news:BE%Bb.1657 $Uz.54556@news7 .onvoy.net...
              > >[color=darkred]
              > >>@SM wrote:
              > >>>if(truc!=fal se || !truc.closed) {truc.close(); truc=false;}[/color][/color]
              >
              > This should have read:
              > if(truc!=false && !truc.closed) {truc.close(); truc=false;}[/color]

              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)
              [color=blue]
              >
              >[color=green][color=darkred]
              > >>Thanks, I guess I'll just have to with a new window rather than an alert.[/color]
              > >
              > > Yeah, but be careful... Popup blockers will try to stop you from doing
              > > this...[/color][/color]

              tant pis pour ceux là !
              They have to choose a clever blocker ! tremendous !
              [color=blue]
              > 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. ;)[/color]
              [color=blue]
              >
              >
              > --
              > Justin Koivisto - spam@koivi.com
              > PHP POSTERS: Please use comp.lang.php for PHP related questions,
              > alt.php* groups are not recommended.[/color]

              --
              *************** *************** *************** *************** **
              Stéphane MORIAUX : mailto:stephane OTER-MOImoriaux@wana doo.fr
              Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)

              *************** *************** *************** *************** **


              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: alert() and message window

                @SM wrote:
                [color=blue]
                > Justin Koivisto a ecrit :[color=green]
                >> Brian wrote:[color=darkred]
                >> > "Justin Koivisto" <spam@koivi.com > wrote in message
                >> > news:BE%Bb.1657 $Uz.54556@news7 .onvoy.net...
                >> >
                >> >>@SM wrote:
                >> >>>if(truc!=fal se || !truc.closed) {truc.close(); truc=false;}[/color]
                >>
                >> This should have read:
                >> if(truc!=false && !truc.closed) {truc.close(); truc=false;}[/color]
                >
                > 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)[/color]

                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,heig ht=200,resizabl e=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,heig ht=200,resizabl e=0');
                if (truc)
                {
                truc.document.o pen();
                truc.document.w rite(debut + title + '<\/h1>\n' + text + fin);
                truc.document.c lose();
                }
                }
                [color=blue]
                > --[/color]

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


                PointedEars

                Comment

                • @SM

                  #9
                  Re: alert() and message window

                  Thomas 'PointedEars' Lahn a ecrit :
                  [color=blue]
                  > @SM wrote:
                  >[color=green]
                  > > Justin Koivisto a ecrit :[color=darkred]
                  > >> Brian wrote:
                  > >> > "Justin Koivisto" <spam@koivi.com > wrote in message
                  > >> > news:BE%Bb.1657 $Uz.54556@news7 .onvoy.net...
                  > >> >
                  > >> >>@SM wrote:
                  > >> >>>if(truc!=fal se || !truc.closed) {truc.close(); truc=false;}
                  > >>
                  > >> This should have read:
                  > >> if(truc!=false && !truc.closed) {truc.close(); truc=false;}[/color]
                  > >
                  > > 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)[/color]
                  >
                  > 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'.[/color]

                  I absolutly agree all what you say,
                  However you never know what a newbie can do ;-))
                  [color=blue]
                  > Thus the above should read:
                  >
                  > if (truc && !truc.closed) truc.close();[/color]

                  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 ;-))
                  [color=blue]
                  > truc = false;
                  >
                  > assignment can be obviously omitted, since it is overwritten by
                  > the next statement anyway:[/color]

                  ???? 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 )
                  [color=blue]
                  > 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:[/color]

                  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).
                  [color=blue]
                  > var truc = null;
                  >
                  > function alarme(title, text)
                  > {
                  > if (!(truc && !truc.closed))
                  > truc = window.open('', '', 'width=300,heig ht=200,resizabl e=0');
                  > if (truc)
                  > {
                  > truc.document.o pen();
                  > truc.document.w rite(debut + title + '<\/h1>\n' + text + fin);
                  > truc.document.c lose();
                  > }
                  > }
                  >[color=green]
                  > > --[/color]
                  >
                  > The trailing space is still missing from
                  > what can become a signature separator.[/color]

                  Oh ! of course ! I'll try to think it
                  [color=blue]
                  > PointedEars[/color]

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

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: alert() and message window

                    @SM wrote:
                    [color=blue]
                    > Thomas 'PointedEars' Lahn a ecrit :[color=green]
                    >> 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'.[/color]
                    >
                    > I absolutly agree all what you say,
                    > However you never know what a newbie can do ;-))[/color]

                    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.
                    [color=blue][color=green]
                    >> Thus the above should read:
                    >>
                    >> if (truc && !truc.closed) truc.close();[/color]
                    >
                    > 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 ;-))[/color]

                    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.
                    [color=blue][color=green]
                    >> truc = false;
                    >>
                    >> assignment can be obviously omitted, since it is overwritten by
                    >> the next statement anyway:[/color]
                    >
                    > ????[/color]

                    Your `?' key is borken.
                    [color=blue]
                    > tell it to IE[/color]

                    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).
                    [color=blue][color=green]
                    >> 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:[/color]
                    >
                    > I don't understand the real difference [ if(truc) ]
                    > By the fact if a window is opened, it would be to use it, no?[/color]

                    Not necessary. We do not have modal windows here which shows, as
                    I realized later, another problem with user-defined message windows.
                    See below.
                    [color=blue]
                    > Do you mean if the popup is closed, system ressources for a new popup
                    > are still running ?[/color]

                    Yep.
                    [color=blue]
                    > I suppose that the complete JS code is running in system
                    > all long the page is not closed (unloaded).[/color]

                    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])
                    [color=blue][color=green]
                    >> var truc = null;
                    >>
                    >> function alarme(title, text)
                    >> {
                    >> if (!(truc && !truc.closed))
                    >> truc = window.open('', '', 'width=300,heig ht=200,resizabl e=0');
                    >> if (truc)
                    >> {
                    >> truc.document.o pen();
                    >> truc.document.w rite(debut + title + '<\/h1>\n' + text + fin);
                    >> truc.document.c lose();
                    >> }
                    >> }[/color][/color]

                    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,heig ht=200,resizabl e=yes,dependent =yes');
                    if (truc)
                    {
                    truc.document.o pen("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.w rite(debut + title + '<\/h1>\n' + text + fin);

                    truc.document.c lose();

                    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.
                    [color=blue][color=green][color=darkred]
                    >> > --[/color]
                    >>
                    >> The trailing space is still missing from
                    >> what can become a signature separator.[/color]
                    >
                    > Oh ! of course ! I'll try to think it[/color]

                    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

                    Comment

                    Working...