Advertise Here

Author Topic: [Code] Replace broken image with an image (default image)  (Read 2544 times)

0 Members and 1 Guest are viewing this topic.

Offline Colette Brunel

  • SMF For Free Sr. Member
  • *
  • Posts: 424
    • View Profile

  • Total Badges: 17
    Badges: (View All)
    Poll Voter Level 4 Fourth year Anniversary Windows User Topic Starter
[Code] Replace broken image with an image (default image)
« on: November 25, 2008, 01:41:13 pm »
Do you have a customized template that has images from all over the place? Have you ever had a problem where the image was moved/deleted, and your template screws up since the image failed to load?

Well, I have a solution! Every time you have an image that is unable to load, your templates will load a "default" image in place of it.

Make sure you have a reference to jQuery in your headers.

Code: [Select]
<script src="/jquery.js"></script>
In your headers, add the following:

Code: [Select]
<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
$("img").error(function () {
  $(this).unbind("error").attr("src", "http://somesite.com/images/broken.gif");
}); // ]]></script>

Replace "http://somesite.com/images/broken.gif" with the full path to the "default" loaded image.
« Last Edit: November 25, 2008, 04:42:45 pm by ccbtimewiz »

Offline [JeReMy]

  • SMF For Free Master
  • *
  • Posts: 1174
  • www.ourhangout.org
    • View Profile
    • ourhangout

  • Total Badges: 16
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: Replace broken image with an image (default image)
« Reply #1 on: November 25, 2008, 02:04:30 pm »
hey thanks ccb im definatley gonna use it

Offline - Lawrence -

  • SMF For Free Hero
  • *
  • Posts: 549
    • View Profile

  • Total Badges: 15
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: [Code] Replace broken image with an image (default image)
« Reply #2 on: November 26, 2008, 03:38:15 pm »
Nice code.  8) I will use it!

 

Related Topics

  Subject / Started by Replies Last post
9 Replies
3017 Views
Last post April 27, 2006, 07:12:38 pm
by COPABOD
8 Replies
2703 Views
Last post April 06, 2008, 06:07:33 pm
by Abstract
5 Replies
2307 Views
Last post May 06, 2009, 05:03:06 pm
by Seldom Fail
9 Replies
3619 Views
Last post June 02, 2009, 04:18:54 pm
by 4markie
2 Replies
1536 Views
Last post February 11, 2018, 10:00:08 am
by ermenton