Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

JavaScript headscratching

Options
  • 02-05-2002 10:08am
    #1
    Registered Users Posts: 14,148 ✭✭✭✭


    Hey Guys,

    trying to fix cross-browser problems (with someone elses code who is LONGGG gone and there' sbugger all commenting or documentation), and since I know not a great deal about javascript am up sh*t creek so to speak.

    code:
    function MM_preloadImages()
    { //v3.0
    var d = document ;
    if(d.images)
    {
    if(!d.MM_p)
    d.MM_p = new Array() ;

    var i, j = d.MM_p.length, a = MM_preloadImages.arguments ;

    for(i = 0; i < a.length; i++)
    if (a.indexOf("#")!=0)
    {
    d.MM_p[j] = new Image ;
    d.MM_p[j++].src = a ;
    }
    }
    }

    Now, what I need to know is .... where the f*ck is the MM_p variable coming from, along with that "indexOf" crap.

    The function is called and is passing in a .gif file incidentally. If I put in an alert to show the values of d.MM_p.length and 'a', they're empty, so wtf??

    :confused:


Comments

  • Registered Users Posts: 2,660 ✭✭✭Baz_


    code looks pretty f**ked up to me, it looks like the code that dreamweaver generates when you implement the preloading of images with that.

    tbh with you i tried to understand that dreamweaver code before and gave it up believing it would be easier to write my own less mystic function. Maybe someone with more patience can explain it *shrug*


  • Registered Users Posts: 1,393 ✭✭✭Inspector Gadget


    Let's see. The d.MM_p variable is initialised here:
    if(!d.MM_p) 
    d.MM_p = new Array();
    
    (where "d" refers to the current document; if MM_p doesn't exist, initialise it as an array)

    The IndexOf() method is how you find a substring in another string in Javascript. "a" is defined as being whatever arguments you pass to MM_preloadimages, i.e. MM_preloadimages(argument1, argument2, ... argumentn) called, probably frequently, elsewhere in the page.

    Hope this helps,
    Gadget


Advertisement