Solved

Html and asp.net mvc

Posted on 2016-09-18
3
49 Views
Last Modified: 2016-09-18
HI Guys,

I'm showing picture in my html page in this way:

<img src="smiley.gif" alt="There is no picture" width="42" height="42">

Open in new window


The issue I have is when the picture doesn't exist I would like to alt="There is no picture" message.
I'm getting the message but I'm getting also little thumb nail which I don't need.

There is work around it to make just the message to appear in case picture doesn't exist?


Thanks,
0
Comment
Question by:Moti Mashiah
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
Snarf0001 earned 500 total points
ID: 41804021
There's no handy css or js property you can hook into do validate that, but there is a js event.
The images if they don't download properly will throw an "error" event (onerror),
You would have to hook up an event handler for that to change the class or hide the image if and when that is thrown.
0
 
LVL 1

Author Comment

by:Moti Mashiah
ID: 41804057
Now the question is how do I do it.

Can you send some code example?

Thanks,
0
 
LVL 1

Author Closing Comment

by:Moti Mashiah
ID: 41804066
Thank you for the idea.

Here is how I solved it.

var img = document.getElementById("myImg");
img.onerror = function () {
    this.style.display = "none";
}
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Client Validating 2 date fields, required & comparison 1 30
Select case on click 3 16
Hide Table in merge 3 12
Alert after MVC form submitted 1 9
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question