`
wangangie12
  • 浏览: 45534 次
  • 性别: Icon_minigender_2
  • 来自: 厦门
最近访客 更多访客>>
社区版块
存档分类
最新评论

iframe 自动高、宽度设置 总结

阅读更多

        function iFrameHeight() {     var ifm= document.getElementById("iframepage");     var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;     if(ifm != null && subWeb != null) {    ifm.height = subWeb.body.scrollHeight;  }     }     ================================================== =====================================  ================================================== =====================================   function resize(){var h=50; try{ if(ifr_lb&&ifr_lb.document&&ifr_lb.document.body){ var o=ifr_lb.document.body; var h=o.scrollHeight + (typeof(o.clientTop)== 'number' ?o.clientTop * 2 : 0);} } catch(e){var h=50;window.status=e.description;} if(h  ================================================== ====================================  function reinitIframe(){ var iframe = document.getElementById("frame_content"); try{ iframe.height =  iframe.contentWindow.document.documentElement.scro llHeight; }catch (ex){} } window.setInterval("reinitIframe()", 200);  Check Height function checkHeight() { var iframe = document.getElementById("frame_content"); var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scro llHeight; alert("bHeight:" + bHeight + ", dHeight:" + dHeight); }  Toggle Overlay      function toggleOverlay() { var overlay = document.getElementById('overlay'); overlay.style.display = (overlay.style.display == 'none') ? 'block' : 'none'; }  function reinitIframe(){var iframe = document.getElementById("frame_content"); try{ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scro llHeight; var height = Math.max(bHeight, dHeight); iframe.height =  height; }catch (ex){} } window.setInterval("reinitIframe()", 200); 最终代码
  
  
  function reinitIframe(){
  var iframe = document.getElementById("frame_content");
  try{
  var bHeight = iframe.contentWindow.document.body.scrollHeight;
  var dHeight = iframe.contentWindow.document.documentElement.scro llHeight;
  var height = Math.max(bHeight, dHeight);
  iframe.height =  height;
  }catch (ex){}
  }
  window.setInterval("reinitIframe()", 200);
  
  ================================================== ==================================
  
    
    
    
  
  
  用到了CSS的text-shadow属性。IE全系列都不支持,火狐、chrome都支持。
  css2的时候已经有了text-shadow这个属性,但是css2.1的又删除了这个属性,css3又重新使用了这个属性;text-shadow:阴影水平偏移值(可取正负值); 阴影垂直偏移值(可取正负值);阴影模糊值;阴影颜色
  marginHeight="100%" ====自动宽度 火狐和IE下
  ================================================== =================================
  引入代理代理页面c.html与a.html所属相同域A,c.html是A域下提供好的中间代理页面,假设c.html的地址:www.taobao.com/c.html,它负责读取location.hash里面的width和height的值,然后设置与它同域下的a.html中的iframe的宽度和高度.
  代码如下:
  a.html代码
  首先a.html中通过iframe引入了b.html  b.html代码     
  var b_width = Math.max(document.documentElement.clientWidth,docu ment.body.clientWidth);
  var b_height = Math.max(document.documentElement.clientHeight,doc ument.body.clientHeight);
  var c_iframe = document.getElementById("c_iframe"); //liehuo.net
  c_iframe.src = c_iframe.src+"#"+b_width+"|"+b_height; //http://www.taobao.com/c.html#width|height"
  }
  
  
   
  c.html代码     
  var b_iframe = parent.parent.document.getElementById("b_iframe");
  var hash_url = window.location.hash;
  var hash_width = hash_url.split("#")[1].split("|")[0]+"px";
  var hash_height = hash_url.split("#")[1].split("|")[1]+"px";
  b_iframe.style.width = hash_width;
  b_iframe.style.height = hash_height;
   
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics