Iframe 自适应高度(js)

  • 兼容的Iframe自适应高度
    function setIframeHeight(id){
          try{
            var iframe = document.getElementById(id);
            if(iframe.attachEvent){
              iframe.attachEvent("onload", function(){
                iframe.height =  iframe.contentWindow.document.documentElement.scrollHeight;
              });
              return;
            }else{
              iframe.onload = function(){
                iframe.height = iframe.contentDocument.body.scrollHeight;
              };
              return;                
            }    
          }catch(e){
            throw new Error('setIframeHeight Error');
          }
        }

你可能感兴趣的:(JS)