Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    replace broken image

    if you want to replace a broken image with something else based on the fact that its broken when viewed. How would you refer to "broken" in the code???

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <img src="myimage.jpg" onError="this.src='anotherimage.jpg'">
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #3
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    you need to use javascript.

    if you're writing it in the html, it would look something like this.

    <img onerror="this.src='theImageYouWantToChangeTo.gif';" src="theImageThatIsBroken.gif">

    please note that the order of the attributes is important, and that no matter what other attributes you use, like width or height, the green part, has to come before the red part.
    Last edited by joh6nn; 04-01-2003 at 02:50 AM.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    Spain
    Posts
    420
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by joh6nn
    please note that the order of the attributes is important, and that no matter what other attributes you use, like width or height, the green part, has to come before the red part.
    strange. It always worked for me no matter where the "onerror" was
    Don't resist to assimilation. Billions of Borgs can't be wrong!

  • #5
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    Borgtex, i rarely code the onload or onerror events into html as attributes; i'm basing that on how it works between <script> tags. if you assign a source to an image before you assign it an onload or onerror event, then the image may finish loading, before the event has been assigned, and the event won't ever fire, even if the activity it's supposed to monitor has occurred. for safety's sake, i've assumed that it works the same way as an attribute, although to be honest, i have no idea if it works that way or not.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #6
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Hey, this is pretty interesting...

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    North East England
    Posts
    853
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can do this in php too..
    PHP Code:
    <?
    $var 
    = @fopen("http://www.youraddress.com/image.jpg","r"); //-- url or path
    if ($var){
    print 
    "<img src=\"image.jpg\"/>"//-- wanted image here
    }else{
    print 
    "<img src=\"alternative-image.gif\"/>"//--alternative image here

    ?>
    [+] Computer/PC issues [+] Silverpaw3D
    ------------------------------------------------
    Never buy a dwarf with learning disabilities...

    ...it's not big, and it's not clever.

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    Iowa / Notre Dame
    Posts
    538
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is very interesting! But just wondering...how practical is this? I mean, if you have an image coded into your source hopefully you have that image uploaded too. So if that image doesn't load what are the chances of another image loading?

    I kind of was confused with my own example there, but it just seems like this might only be for testing purposes rather than for actual public use?
    My Site {Mike's Adventures}

    Yikes, forums are almost too much fun.

  • #9
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    well, i would it set it up something like this:

    image.onerror = function() {
    this.attempts = (this.attempts == 'undefined') ? 1 : 2;
    if (this.attempts == 1) { this.src = this.src; }
    else { this.visibility = 'hidden'; }
    }
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #10
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Originally posted by pardicity3
    This is very interesting! But just wondering...how practical is this? I mean, if you have an image coded into your source hopefully you have that image uploaded too. So if that image doesn't load what are the chances of another image loading?

    I kind of was confused with my own example there, but it just seems like this might only be for testing purposes rather than for actual public use?
    For a server to server notification...
    If I have a web server running my site, and to tell people that go to my site that my game (or another) server is up, I will display an image from that computers webserver (could just host that one image) that says "UP".

    And if it's not there, then it will display the image from my computer, "DOWN"...

    I think that makes sence....

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    Iowa / Notre Dame
    Posts
    538
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That makes very much sense indeed. Thanks for the great example!
    My Site {Mike's Adventures}

    Yikes, forums are almost too much fun.

  • #12
    New Coder
    Join Date
    Jun 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Na, see

    The code that calls the image contains a function and include
    see theres like 200 of these and not all have images from the database that its calling from and i dont want them to show broken images on the ones i havent gotten to yet. I'm building this directly off the server so its not a matter of uploading.

    <img onerror="this.src='http://www.website.com/images/boxes and lines/whitebox.gif';" src="http://www.website.com/products<%= oWEB.fnGet_Product_Image_URL(CStr(TWO("PRODUCT_ID"))) %>" width="70">

  • #13
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    wait, what's the problem?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #14
    New Coder
    Join Date
    Jun 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no problem


  •  

    Posting Permissions

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