2

I have a script that works fine in everything but IE8/9. The weird thing is, when I open the developer tools and console in IE to deb, and then refresh the page as it says to, the script runs fine. What am I missing? Any idea what IE doesn't like about this script?

One other note - the script doesn't load until the window loads as I need to measure the height of images, so maybe that is part of the problem?

Thanks for any help

$(window).load(function(){


     function offsetElement(element, container){
            if ( $(window).width() > 767 ) {

                $(element).each(function(index,value){

                    var snapImage = $(this),
                        snapImageHeight = snapImage.height(),
                        containerHeight = snapImage.closest(container).outerHeight(),
                        topOffset = (containerHeight - snapImageHeight) / 2;

                    $(this).css({ 'top' : topOffset });

                 });
            }

     }


        offsetElement('.snapshot', '.event');
        offsetElement('.dot', '.event'); 

    function activeSnap(){ return offsetElement('.snapshot', '.event'); }
    function activeDot(){ return offsetElement('.dot', '.event'); }


     $(window).resize(function(){
        activeSnap();
        activeDot();
     });


});
Ben
  • 5,283
  • 9
  • 35
  • 44
  • which over of `jQuery` are you using? have you try using `window.onload` see if IE works with it? – jasonslyvia Sep 12 '13 at 01:49
  • 4
    Is that the whole code? If not, look for console.log anywhere, and remove it. – bfavaretto Sep 12 '13 at 02:02
  • Given the description of the problem, it is almost certain to be a `console` call somewhere in the code. See also http://stackoverflow.com/questions/7742781/why-javascript-only-works-after-opening-developer-tools-in-ie-once – Spudley Sep 12 '13 at 13:39

3 Answers3

1

$(window).load() should be using the built in onload function so that shouldn't be the problem. It could be your jQuery version, jQuery 2.X does not support Internet Explorer 6, 7, or 8. Make sure you're using jQuery 1.X for compatibility

Graham Walters
  • 2,054
  • 2
  • 19
  • 30
0

Use $(document).ready() instead of $(window).load().

Rocklan
  • 7,888
  • 3
  • 34
  • 49
  • 1
    Thanks for the reply. I used .load because I have images that need to be fully loaded before the script runs, as the main feature of the script is to measure the height of images. If I use document.ready I get incorrect measurements. – Ben Sep 12 '13 at 02:00
0

which over of jQuery are you using? have you try using window.onload see if IE works with it? – jasonslyvia 35 mins ago

Thanks @jasonslyvia, all I did was replace $(window).load for window.onload and it works fine now.

Ben
  • 5,283
  • 9
  • 35
  • 44