Image Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Griffiths

    #1

    Image Question

    Is there a Javascript way to check if an image has been rendered on the
    page ? For example if my HTML includes :

    <img name="testImg" src="images/one.gif">

    is there anyway to tell using Javascript post page load if that image
    has actually been loaded ?

  • Mick White

    #2
    Re: Image Question

    Greg Griffiths wrote:
    [color=blue]
    > Is there a Javascript way to check if an image has been rendered on the
    > page ? For example if my HTML includes :
    >
    > <img name="testImg" src="images/one.gif">
    >
    > is there anyway to tell using Javascript post page load if that image
    > has actually been loaded ?
    >[/color]

    <img onload="functio n(){whatever}"
    Mick

    Comment

    • Andrew Urquhart

      #3
      Re: Image Question

      "Mick White" <mwhite13@BOGUS rochester.rr.co m> wrote in message
      news:KCv_b.8270 2$%72.52759@twi ster.nyroc.rr.c om...[color=blue]
      > Greg Griffiths wrote:
      >[color=green]
      > > Is there a Javascript way to check if an image has been rendered on the
      > > page ? For example if my HTML includes :
      > >
      > > <img name="testImg" src="images/one.gif">
      > >
      > > is there anyway to tell using Javascript post page load if that image
      > > has actually been loaded ?
      > >[/color]
      >
      > <img onload="functio n(){whatever}"
      > Mick[/color]

      Just a general note:
      Some browsers don't support the onload event for images (i.e. Opera) so be
      sure to provide a graceful and accessible alternative if possible.
      --
      Andrew Urquhart
      - FAQ: http://jibbering.com/faq
      - Archive: http://groups.google.com/groups?grou...ang.javascript
      - Reply: https://www.andrewu.co.uk/about/cont...=newsgroup_clj


      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/2004


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Image Question

        "Andrew Urquhart" <reply_via_cont act_page@websit e_in.sig> writes:
        [color=blue]
        > Just a general note:
        > Some browsers don't support the onload event for images (i.e. Opera)[/color]

        Opera does support the onload event. There was a bug somewhere around
        7.11 (or was it 7.20) where it failed, but in general it works (and did
        in Opera 6 as well).
        [color=blue]
        > so be sure to provide a graceful and accessible alternative if
        > possible.[/color]
        /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

        • Andrew Urquhart

          #5
          Re: Image Question

          "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
          news:hdxh2vok.f sf@hotpop.com.. .[color=blue]
          > "Andrew Urquhart" <reply_via_cont act_page@websit e_in.sig> writes:
          >[color=green]
          > > Just a general note:
          > > Some browsers don't support the onload event for images (i.e. Opera)[/color]
          >
          > Opera does support the onload event. There was a bug somewhere around
          > 7.11 (or was it 7.20) where it failed, but in general it works (and did
          > in Opera 6 as well).[/color]


          Doh, I'm using 7.23 and yes it does work!

          Actually I now know why I've always thought it didn't and it's not because
          of the bug you mention, it's because I've always tested for the method to
          see if it exists before I try and use it, and it's only just dawned on me
          that Opera and other browsers handle this differently. For example:

          var objImg = new Image();
          objImg.src = "http://www.andrewu.co. uk/pix/xml.gif";
          alert(typeof objImg.onload);
          objImg.onload = function() {var dummy = null};
          alert(typeof objImg.onload);

          IE has a native or 'placeholder' onload method and returns "object" for the
          first alert whereas Opera and Mozilla return "undefined" . I always took the
          latter browsers behaviour to mean that they didn't support the event, in the
          same vain as:

          if (document.getEl ementById) {
          // Method supported
          }
          else {
          // Method not supported
          }
          --
          Andrew Urquhart
          - FAQ: http://jibbering.com/faq
          - Archive: http://groups.google.com/groups?grou...ang.javascript
          - Reply: https://www.andrewu.co.uk/about/cont...=newsgroup_clj


          Comment

          • greg griffiths

            #6
            Re: Image Question

            That is all useful - also the ONERROR event - but what I was looking for
            was a script that I could run once a page has loaded - as the content
            is being sourced from another server and the images may be unavailable
            due to permissions - that would process each image and then detect the
            missing ones.



            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            Working...