Hello,
I have seen MM_preload_images() in many HTML files but I am not able to understand why it is used. It is loaded on load event of body. What does it do actually?
Here is the code of MM_preloadImages() function,

function MM_preloadImages() { 
   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[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

Please help me. Thanks in advance.

    I looks like it is creating an array of images found in the page.

    I am guessing that the function is in a .js file and that may cache the images for faster page loading when a user clicks a link that takes them to other pages on the same site that reuse the same images.

    This makes it a bit more readable

    function MM_preloadImages() { 
        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[i].indexOf("#") != 0) {
    
                d.MM_p[j] = new Image;
    
                d.MM_p[j++].src = a[i];
    
            }
        }
    }
    }
    

    Should note that the "indexOf" needs to be defined somewhere, as not all browsers support it.

      It's Dreamweaver-generated boilerplate code that does as Krik describes ("MM" for Macromedia). Possibly cut-and-pasted by others since.

        ok.. thats fine... but what it does actually? i mean to say is it doing some kind of loading of images or something else?

          What you have there is a JavaScript function spit out by Dreamweaver, which automatically means don't use it. Dreamweaver produces the worst JavaScript ever devised by man, beast, or machine.

            JPnyc;10907874 wrote:

            What you have there is a JavaScript function spit out by Dreamweaver, which automatically means don't use it. Dreamweaver produces the worst JavaScript ever devised by man, beast, or machine.

            Has there ever been a piece of software that produces good code?

            I guess I didn't know that was a dreamweaver produced function but I should have guessed, no real programmer would have written code with such poorly readability.

              yes its auto generated(Dreamweaver generated!!!!) code. But what I mean to say is that why it is generating such code? There must be some importance of it.

                Read Krik's first reply.

                And/or have a look at Dreamweaver's documentation (it's online).

                  basically, it's this;

                  if (d.images){ // this is testing for the presence of the images object

                      if(!d.MM_p) {
                  
                          d.MM_p = new Array();// this is testing for the images array, which is also stupid because why would it exist if you didn't create it. It then creates it. Unnecessary and stupid to test for something that only you would've created with code

                  var i, j = d.MM_p.length, a = MM_preloadImages.arguments;// this is setting two variables to the length of the images array. The second half is setting a variable equal to the function arguments, of which there are none.

                  the rest is just preloading the images.

                    Krik;10907896 wrote:

                    Has there ever been a piece of software that produces good code?
                    I guess I didn't know that was a dreamweaver produced function but I should have guessed, no real programmer would have written code with such poorly readability.

                    lol nope. You win that oneπŸ˜ƒ

                      Write a Reply...