Search code examples
javascriptjqueryunobtrusive-javascript

Internet explorer dynamic image loading


I am trying to load images throught javascript. Different browser than IE8 or ie9 it's working fine, but in IE doesn't. If I load the image directly

http://localhost/_eWar/index.php?road=map&createimage=true

it's working fine, but trought javascript

src="index.php?road=map&createimage=true";
 this.img_object.object = $("<img>");
this.img_object.object.unbind('load').
                removeAttr("src").
                removeAttr("width").
                removeAttr("height").
                attr("class","map newMap").
                attr("usemap","#world").
                css({ top: 0, left: 0 }).
                load(function(){
                    me.image_loaded = true;
                    me.img_object.display_width = me.img_object.orig_width = this.width;
                    me.img_object.display_height = me.img_object.orig_height = this.height;

                    if(!me.container.hasClass("iviewer_cursor")){
                        me.container.addClass("iviewer_cursor");
                    }

                    if(me.settings.zoom == "fit"){
                        me.fit();
                    }
                    else {
                        me.set_zoom(me.settings.zoom);
                    }

                    if(me.settings.onFinishLoad)
                    {
                       me.settings.onFinishLoad.call(me);
                    }
                //src attribute is after setting load event, or it won't work
            }).attr("src",src);

I get a "compatible view" message.


Solution

  • I'm not sure why you're resetting and looking at attributes on a new image.

    Here's an easy way to load images:

    function loadSample() {
        var i = new Image()
            i.onload = function() {
                 alert("loaded")  
            }
                i.src = "http://jsfiddle.net/img/logo.png"       
    
    }