Load event for iFrame not fired in IE

前端 未结 7 1516
无人及你
无人及你 2020-12-09 02:46

Why is the load event not fired in IE for iFrames?

Please take a look at this example.

Work perfectly as expected in FF and Chrome, but IE fails

7条回答
  •  借酒劲吻你
    2020-12-09 03:38

    Using the JavaScript code with jQuery from here works if you change the if ($.browser.safari || $.browser.opera) { line to if ($.browser.safari || $.browser.opera || $.browser.msie) {. So you have the following:

    $(function(){
    
        var iFrames = $('iframe');
    
        function iResize() {
    
            for (var i = 0, j = iFrames.length; i < j; i++) {
              iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';}
            }
    
            if ($.browser.safari || $.browser.opera || $.browser.msie) { 
    
               iFrames.load(function(){
                   setTimeout(iResize, 0);
               });
    
               for (var i = 0, j = iFrames.length; i < j; i++) {
                    var iSource = iFrames[i].src;
                    iFrames[i].src = '';
                    iFrames[i].src = iSource;
               }
    
            } else {
               iFrames.load(function() { 
                   this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
               });
            }
    
        });
    

提交回复
热议问题