1

I am getting an error in IE8: Object doesn't support this property or method yet everything works in the other browsers no problem. When IE is refreshed the error goes away and the slideshow displays properly.

Here is the code.

$(window).load(function(){
  $('.flexslider').flexslider({
    animation: "slide",
    start: function(slider){
      $('body').removeClass('loading');
    }
  });
});

The line causing the error is $('.flexslider').flexslider({

I've tried various solutions to no avail. Any suggestions?

4
  • 2
    Have you tried $(document).ready()?
    – kapa
    Commented Dec 20, 2012 at 23:38
  • 2
    Seems like the flexslider plugin isn't getting loaded properly.
    – gen_Eric
    Commented Dec 20, 2012 at 23:38
  • Is jQuery definitely being loaded before the flexslider js? Also are you running any other JS libraries on your page? If so there may be a conflict with the $ operator.
    – Billy Moat
    Commented Dec 20, 2012 at 23:40
  • Did you load the flexslider js? Commented Dec 20, 2012 at 23:40

2 Answers 2

1

Found the answer and it wasn't in the line of code I posted. I was using

<script defer src="scripts/jquery.flexslider.js"></script>

to load the script and I changed it to

<script src="scripts/jquery.flexslider.js"></script>

Everything works fine now.

0
$(function() {
    $(window).load(function() {
        $('.flexslider').flexslider({
          animation: "slide",
          start: function(slider){
          $('body').removeClass('loading');
         }
    });
});

This makes use of jQuery.ready(), which is more reliable than $(window).load() cross-browser.

In fact, you can replace $(window).load() altogether (if you don't need to wait for images or etc).

$(function() {
    $('.flexslider').flexslider({
        animation: "slide",
        start: function(slider){
        $('body').removeClass('loading')
    }
});

Also, make sure the script that includes the flexslider is included in the "head" section of your page. If you include it in the body or load it by creating a DOM node, neither load nor ready will guarantee that it has been executed.

5
  • 1
    But why did you still leave that $(window).load() there? :)
    – kapa
    Commented Dec 20, 2012 at 23:49
  • Maybe the window.load is required to make sure all images are loaded before the code is initialized. Either way, it does not hurt anything to have it there.
    – Sparky
    Commented Dec 20, 2012 at 23:50
  • Good point...your comment came as I was editing the answer :) Commented Dec 20, 2012 at 23:50
  • Actually, Sparky is right - ready does not mean window.load. See this question. If you need to wait for resources (images, etc), then you have to also include window.load. Commented Dec 20, 2012 at 23:55
  • Have tried all of the suggestions. Even moved code around and still displays an error only in IE8. Works fine in all other browsers. In IE8 if you navigate off the page then go back everything works fine with no errors. Strange, I am assuming something isn't loading in the proper order but can't figure it out.
    – J Ward
    Commented Dec 26, 2012 at 13:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.