2011-03-09 111 views
1

我想通過JavaScript加載圖像。不同的瀏覽器比IE8或IE9它工作正常,但在IE瀏覽器不。如果我加載圖像直接Internet Explorer動態圖像加載

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

它的正常工作,但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); 

我得到一個 「兼容視圖」 的消息。

+0

嘗試直接的辦法,將其添加到HTML:''它在IE瀏覽器? – 2011-03-09 14:54:12

回答

2

我不確定爲什麼要重新設置並查看新圖像上的屬性。

這裏有一個簡單的方法來加載圖像:

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

} 
+0

簡單是更好,噢 – Alfabravo 2011-03-09 15:39:02