SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot theslip's Avatar
    Join Date
    Jun 2008
    Location
    here
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy eerr help please, hopefully a quick one, unexpected object

    Hi All,

    I've got a jascript issue in the dreaded IE7/8 issue is unexpected object!

    please see below script, any help would be fantastic, thank you!

    <script type="text/javascript">
    function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
    $('<img/>')[0].src = this;
    });
    }
    preload([
    'images/slide1.jpg',
    'images/slide2.jpg',
    'images/slide3.jpg',
    'images/slide4.jpg',
    'images/slide0.jpg'
    ]);
    </script>

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,389
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    I've just tried this code in IE7 and it seemed to work fine. What version of jQuery are you using? I'm not sure if it makes any difference, but I used 1.10.1 in my test.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by theslip View Post
    I've got a jascript issue in the dreaded IE7/8 issue is unexpected object!
    That's an error message that you can expect to see if jQuery hasn't been properly loaded.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I can't reproduce this off the bat - do you have an example page where this is occurring?

    If I may suggest an enhancement to the preload() function - it could be rewritten a little to be a little more performant.

    Code JavaScript:
    function preload(arrayOfImages) {
        var i, $img = $("<img />");
     
        for (i = 0; i < arrayOfImages.length; i++) {
            $img.attr("src", arrayOfImages[i]);
        }
    }

    In this manner the $("<img/>") isn't being instantiated in every loop - this means a new jQuery object is being formed for every image that you want preloaded.

    The for loop could be used instead of the jQuery.each() as it is many times faster than the jQuery.each() loop.
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •