Results 1 to 7 of 7

Thread: Image Broken Javascript

  1. #1
    Registered+
    Join Date
    Nov 2007
    Location
    Devon
    Posts
    58
    Thanks
    1
    Thanked
    1 time in 1 post
    • Ap0llo's system
      • Motherboard:
      • Asus P5K Premium
      • CPU:
      • Intel Core 2 Duo E8400
      • Memory:
      • 2GB Geil Black Widow
      • Storage:
      • 500GB Western Digital SE16
      • Graphics card(s):
      • Zotac GTX 285
      • PSU:
      • Antec 550W Modular
      • Case:
      • Lian Li V1000 Plus
      • Operating System:
      • Vista and XP
      • Monitor(s):
      • Dual 17" Dell
      • Internet:
      • 8mb BT Total Broadband

    Image Broken Javascript

    Hi there,
    I've got a piece of javascript on my website which replaces broken images with a 'Image Unavailable Image' .
    The problem i've got is that it doesnt seem to work in Firefox

    So can anyone think why and help me out?

    Heres the script:

    Code:
    <script language="JavaScript">
    function ImageLoadFailed(pic) {
    pic.src = "noimage.jpg";
    }
    </script>
    And heres how the html image tag is set out:

    Code:
    <a href="linktosite.html"><img src="myimagethatsbroken.jpg" alt="alt_text" width="150" height="113" border="0" OnError="ImageLoadFailed(this)" />
    Thanks
    Rhys

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Image Broken Javascript

    onerror and other similar events are not part of any specification, and thus their functionality is not set in stone. You should opt for a more standardised method for attaching scripted events to the DOM i.e. addEventListener. All defined and normalised in DOM level 2 I might add, so not exactly difficult to figure out.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s

    Re: Image Broken Javascript

    Maybe I'm wrong here, but shouldn't you really be ensuring images do exist?

    What is the context of the usage of 'noimage.gif'?

    I can think of a couple of situations where it might be favorable to perform this replacement, but I would be tempted to do it either via the database, or server side script.

    Is this a plain HTML site? or does it use server side scripting at all? Are the images coming from a db?

  4. #4
    Registered+
    Join Date
    Nov 2007
    Location
    Devon
    Posts
    58
    Thanks
    1
    Thanked
    1 time in 1 post
    • Ap0llo's system
      • Motherboard:
      • Asus P5K Premium
      • CPU:
      • Intel Core 2 Duo E8400
      • Memory:
      • 2GB Geil Black Widow
      • Storage:
      • 500GB Western Digital SE16
      • Graphics card(s):
      • Zotac GTX 285
      • PSU:
      • Antec 550W Modular
      • Case:
      • Lian Li V1000 Plus
      • Operating System:
      • Vista and XP
      • Monitor(s):
      • Dual 17" Dell
      • Internet:
      • 8mb BT Total Broadband

    Re: Image Broken Javascript

    Quote Originally Posted by DougMcDonald View Post
    Maybe I'm wrong here, but shouldn't you really be ensuring images do exist?

    What is the context of the usage of 'noimage.gif'?

    I can think of a couple of situations where it might be favorable to perform this replacement, but I would be tempted to do it either via the database, or server side script.

    Is this a plain HTML site? or does it use server side scripting at all? Are the images coming from a db?
    Hi the site is in XHTML. I'm still quite new to all this web design so if you could perhaps give me an example that would be a great help

  5. #5
    www.dougmcdonald.co.uk
    Join Date
    May 2007
    Location
    Bath
    Posts
    523
    Thanks
    5
    Thanked
    20 times in 20 posts
    • DougMcDonald's system
      • Motherboard:
      • Asus P5B Deluxe
      • CPU:
      • Inter Core 2 Duo E6600
      • Memory:
      • 2 x 2GB - Geil Black Dragon PC6400
      • Storage:
      • 2 x 400GB Samsung Spinpoints (Running in Matrix array) 100GB @ RAID0 + 300GB @ RAID1
      • Graphics card(s):
      • BFG nVidia 8800GTS 320MB OC2
      • PSU:
      • Corsair HX520W modular
      • Case:
      • Lian-Li PC7 II Plus
      • Monitor(s):
      • LG 17" Flat Thingy
      • Internet:
      • Crappy BT 1MB Unreliable wank :s

    Re: Image Broken Javascript

    Since as you mention, you are fairly new to the area then I would assume you are not using anything server side (such as php or asp etc).

    If you are writing xhtml files, and you're writing them all yourself, why don't you just ensure all image links have a file behind them?

    There should be no real need to call javascript to check if files exist, you should really know that when you right the page! And if you know a certain image won't exist, why don't you just hard code the 'noimage.gif' parameter, and update it when the image does exist?

  6. #6
    Registered+
    Join Date
    Nov 2007
    Location
    Devon
    Posts
    58
    Thanks
    1
    Thanked
    1 time in 1 post
    • Ap0llo's system
      • Motherboard:
      • Asus P5K Premium
      • CPU:
      • Intel Core 2 Duo E8400
      • Memory:
      • 2GB Geil Black Widow
      • Storage:
      • 500GB Western Digital SE16
      • Graphics card(s):
      • Zotac GTX 285
      • PSU:
      • Antec 550W Modular
      • Case:
      • Lian Li V1000 Plus
      • Operating System:
      • Vista and XP
      • Monitor(s):
      • Dual 17" Dell
      • Internet:
      • 8mb BT Total Broadband

    Re: Image Broken Javascript

    thats probably a good idea actually!
    This is what happens when you get to carried away with scripts i guess

  7. #7
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Image Broken Javascript

    Bear in mind that each request a page makes will return its corresponding status code. You should then be able to perform manipulation of the the returned image on the server without need of a server-side scripting language (i.e. somthing like apaches rewrite module or ISAPI rewrite). You would need to look at the request content type (image/jpg for e.g.) and the request status code. If it's a 404 for example you could then point the rewrite engine to your alternative file.
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 06-11-2006, 12:05 PM
  2. acronis true image 9.0
    By lodore in forum Software
    Replies: 3
    Last Post: 18-03-2006, 10:05 AM
  3. Short term Image hosting
    By oshta in forum General Discussion
    Replies: 8
    Last Post: 02-11-2005, 04:50 PM
  4. Image problems in IE (probably CSS related)
    By Dorza in forum Software
    Replies: 4
    Last Post: 08-05-2005, 11:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •