1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Placeholder for broken images

Discussion in 'XenForo Suggestions' started by Nuno, Aug 8, 2015.

  1. Nuno

    Nuno Active Member

    Hello,

    I hate to see posts with broken images, so I end up using a simple jquery script that I found in stackoverflow to replace the error image with a placeholder:

    So, before </body> add:

    Code:
    <script>
    jQuery("img.bbCodeImage").one('error', function () {
        jQuery(this).attr("src", "/styles/default/xenforo/placeholder.jpg");
    }).each(function () {
        if (this.complete && !this.naturalHeight && !this.naturalWidth) {
            $(this).triggerHandler('error');
        }
    });
    </script>
    Don't forget to upload the placeholder image to your server!

    I placed this in the suggestion forum so this can be added to the default theme and because I don't have privileges to posts this in the tips section :)
     

    Attached Files:

    gldtn, Fred., maszd and 5 others like this.
  2. Amin Sabet

    Amin Sabet Well-Known Member

    Thanks for this!

    If you don't want to edit page_container to put this before </body>, it works to put it in the ad_thread_view_below_messages template.
     
    maszd and Nuno like this.

Share This Page