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;
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值