SMF For Free Support Forum

SMF For Free Support => SMF For Free Codes and Support => Topic started by: Colette Brunel on November 25, 2008, 01:41:13 pm

Title: [Code] Replace broken image with an image (default image)
Post by: Colette Brunel 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.
Title: Re: Replace broken image with an image (default image)
Post by: [JeReMy] on November 25, 2008, 02:04:30 pm
hey thanks ccb im definatley gonna use it
Title: Re: [Code] Replace broken image with an image (default image)
Post by: - Lawrence - on November 26, 2008, 03:38:15 pm
Nice code.  8) I will use it!