iframe onload函数在IE中不起作用

时间:2011-10-04 15:03:30

标签: javascript

function showHotelbewertung(W3CElement, objCode) {
   var iframe = document.createElement("iframe"),
       img = document.createElement("img");

       W3CElement.style.position = "relative"

       iframe.className = "bewertung_iframe"  
       iframe.id = "bewertung_iframe"  
       iframe.src = "http://example.com&code="+objCode;
       W3CElement.appendChild(iframe);  

       iframe.onload = function() {
         //var height=iframe.contentWindow.document.body.scrollHeight;
         alert('')
         W3CElement.removeChild(img);
         iframe.style.cssText = "width:100%;height:400px";
       }

       img.src = "assets/images/loader.gif";
       img.style.cssText = "position:absolute;top:15px;left:300px";
       W3CElement.appendChild(img);
}

它在FF中工作正常,但iframe.onload在IE中不起作用。

2 个答案:

答案 0 :(得分:1)

你有没有尝试过这样的事情?

setTimeout(function() {
       iframe.onload = function() {
         //var height=iframe.contentWindow.document.body.scrollHeight;
         alert('');
         W3CElement.removeChild(img);
         iframe.style.cssText = "width:100%;height:400px";
       }
}, 0);

答案 1 :(得分:0)

frame.attachEvent('onload',function(){CustomFunction()});