Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:03:04+00:00 2026-05-31T20:03:04+00:00

Some people set default src to img element in the following way: <img src=foo.jpg

  • 0

Some people set default src to img element in the following way:

<img src="foo.jpg" onerror="this.src='default.jpg'" />

I think it’s not the best way because a additional http request will be sent when onerror event be fired, and our log component will log the worthless error message.

I think I can do in following way:

Create a HttpHandler(.ashx) to send appropriate image to client. So I can write a img in page like this: <img src=‘ImageHandler.ashx?id=foo.jpg’/>. App will check whether the image(foo.jpg) exists or not, then decides to send foo.jpg or default.jpg.

Is it right? Do you have better resolution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:03:05+00:00Added an answer on May 31, 2026 at 8:03 pm

    yeah there is a way :

    <object data="http://aaa.com/does-not-exist.png">
        <img src="http://aaa.com/content/img/so/logo.png">
      </object>
    

    how ever you should tyry it with the Browser compatibility.

    another solutiuon is :

    <style type="text/css">
    img {
       background-image: url('/images/default.png')
    }
    </style>
    

    if the inside image doesn’t exists , the outer will be performed.

    After a srarch : this question was asked before here :

    Inputting a default image in case the src attribute of an html <img> is not valid?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since some people got me wrong: this is not about saving. The problem is
Some people have mentioned RockScroll and MetaScroll in This Question , but those only
I know of some people who use git pull --rebase by default and others
Pretty sure some people encountered this problem before. Followed all the instructions to setup
Alright, I have some weird behavior and this question goes to the people out
I was wondering if some people could help, I have this code in my
Hii People, i want to set up a default exception handler for all application
Let me try this again, because I'm not sure people got that I was
Some people at the office feel uncomfortable having to disable macro security for outlook
Some people load the google places api with a client parameter, example : <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.