views:

232

answers:

3

I have a 3rd website (Confluence) which references images which are secured by a login.

If the current user is logged in the image is shown if not the image url would redirect to a login form.

Example

<img src="secure/myimage.gif" />

When you enter this url in the browser a redirect to the login page is done.

The problem now: IE shows a the dreaded red X icon for the image even though there should be just nothing (like in Firefox). Anyone knows how to get around this?

+1  A: 

Here are some solutions:

  1. redirect the page that contains secured images to the login form
  2. the image service returns a default one if security check failed.
  3. ship a hacked IE to your client with the red X replaced by a blank one like Firefox you mentioned.
Codism
+5  A: 

Use the onError event to set a default image.

This will function in any browser.

The blank image show in FF is a quirk of FF because the received file isn't an image it should report an error.

Paulo Santos
Or remove the image completely if you don't want anything, eg.: `onerror="this.parentNode.removeChild(this)"`.
bobince
Thanks for the hint, I'm using this jQuery script to replace all broken images with a defined placeholder image. Works in IE/FF/Chrome:<script type="text/javascript" lang="javascript">jQuery(window).bind('load', function() {jQuery('img').each(function() { if((typeof this.naturalWidth != "undefined" }}); })</script>
hubertg
Works perfect, Cheers! `<img src="pic.jpg" onerror="this.src='default.jpg'"/>`
runrunraygun
A: 

I found a fine solution using jQuery: This script replaces all "broken" images with a defined placeholder. Works perfect in IE/FF/Chrome

<script type="text/javascript" lang="javascript">

jQuery(window).bind('load', function() {
jQuery('img').each(function() {
    if((typeof this.naturalWidth != "undefined" &&
        this.naturalWidth == 0 ) 
        || this.readyState == 'uninitialized' ) {
        jQuery(this).attr('src', 'placeholder.gif');
    }
}); 
})

</script>
hubertg