Solved

Html and asp.net mvc

Posted on 2016-09-18
3
56 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 23

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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