views:

1260

answers:

4

I have a gallery I quickly coded up for a small site, and under Firefox 3 and Safari 3 works fine. But when I test on my old best friend IE7, it seems to not fire the imageVar.onload = function() { // code here }.. which I want to use to stop the load effect and load the image. The site is at

http://www.stationhotels.com.au/new/?page=accommodation

Please bare in mind...

  • I know the thumbnails are just scaled down version of the larger images. When the images are finalised by the client I am going to create proper thumbnails.
  • This is my first attempt to try and get out of procedural JavaScript for the most part.. so please go easy and kindly let me know where my code sucks!

Thank you very much

+2  A: 

Cross browser event support is not so straightforward due to implementation differences. Since you are using jQuery at your site, you are better off using its events methods to normalize browser support:

instead of:

 window.load = function(){ 
      //actions to be performed on window load
 }

 imageViewer.image.onload = function(){ 
     //actions to be performed on image load
 }

Do:

$(window).load(function(){ 
    //actions to be performed on window load
});

 $(imageViewer.image).load(function(){ 
      //actions to be performed on image load
 });
Eran Galperin
Strange this, some of the gallery is now working... clicking on some image thumbnails makes the image appear to the right but not on other image thumbnails. Sound strange or what?Thank you very much for your input.
alex
+4  A: 

For successful use of Image.onload, you must register the event handler method before the src attribute is set.

Related Information in this Question:

Javascript callback for Image Loading

keparo
how do I do this?
alex
I've added a link to the answer which inludes an example snippet.
keparo
Thank you very much! It worked... I owe you a drink!
alex
A: 

Just to add to the suggestion by Eran to use the jQuery's built in event handlers you can run code when the document is loaded and the DOM is created but before the images are downloaded with:

$(document).ready(function(){
   //your code
});
Vincent Ramdhanie
Thank you, but I've already implemented this.
alex
A: 

This question seems to be a duplicate of one I asked a while ago.

rmeador
apologies, it didnt appear when I typed it in the title and it displays related questions.... and I searched here for it also.
alex