Browsing articles from "November, 2011"
Nov
9

Working with jQuery load() function on images in Internet Explorer 8 and below

One big problem with using load() on images is that it just does not work at all on ie. Now there is a lot of solutions proposed to counter this problem, however most of them are irritating.

Why IE handle load() this way

Simple, IE already cached your image, so it does not need to load it back The 2 most know solution to this are one, adding a random string at the end of the image url, like this:

  1. myImge = $("<img />")
  2.    .attr("src",anyDynamicSource+ "?" + new Date().getTime());

The other solution is to check the height property since if it’s not zero, the image is already loaded:

  1. $('img').each(function() {
  2.     if ($(this).height() > 0) {
  3.        our callback
  4.     } else {
  5.        $(this).load(function() {
  6.          our callback
  7.        });
  8.     }
  9. });

Well these 2…


RSSSome Tweets