AllInWorld99 provides a reference manual covering many aspects of web programming, including technologies such as HTML, XHTML, CSS, XML, JavaScript, PHP, ASP, SQL,FLASH, jQuery, java, for loop, switch case, if, if else, for...of, for...in, for...each,while loop, blogger tips, blogger meta tag generator, blogger tricks, blogger pagination, client side script, html code editor, javascript editor with instant output, css editor, online html editor, materialize css tutorial, materialize css dropdown list,break, continue statement, label,array, json, get day and month dropdown list using c# code, CSS button,protect cd or pendrive from virus, cordova, android example, html and css to make android app, html code play,telerik show hide column, Transparent image convertor, copy to clipboard using javascript without using any swf file, simple animation using css, SQL etc. AllInWorld99 presents thousands of code examples (accompanied with source code) which can be copied/downloaded independantly. By using the online editor provided,readers can edit the examples and execute the code experimentally.


Set alternate image html

     In some situations, the image path set by user may not return any image but null value .
(When image is removed from the provided path or may be due to fault in path provided in the tag.)

Unknown Image in HTML tag

For these situations we can set an alternative image path if the invalid image path.

1) In line HTML
2) Call a Function when error occur

In Line HTML

     In line HTML is used to give alternative image path directly. 


<img src=" Images/Employees/smile.jpg" onerror="this.onerror=null;img/noimg.jpg;" />

Invalid Image URL

Using Function in on error

     Suppose you want to set the same alternate image for a number of img controls and  you are passing the alternate image directly in ‘onerror’ attr for each of these controls .If a situation arise wherein you have to change the alternate image path  ,then you will have to change the image path in each of these controls which may take a lot of time and effort may lead to some errors. So in such situations ,it’s better to use a function in oneerror attr  (as shown in the eg : below ) rather than passing image path directly  wherein you  just have to change the image path in the function once and thus saves a lot of time and effort.




<script>
 function callfun(obj)
 {
        var noimg = "Images/Employees/noimagepath.jpg";
        obj.src=noimg;
}
</script>

<img src=" Images/Employees/erro.jpg" onerror="this.onerror=null;callfun(this);" />

Alternative Image path from function


0 comments:

Post a Comment

Total Pageviews