在一个页面中加载显示 iframe 页面,需要设置 iframe 的宽,每个页面的高度不同,需要根据子页面的高度自动设置全显示。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
   | 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");     } }
  | 
 
      
     
    
      
  
  
    
      
      
        
        致力于网站建设与Web开发。喜欢新事物,关注前后端动态,对新的技术有追求, 做一个优秀的web全栈工程师。