AspNet技术

.Net平台 + C#语言 + Microsoft SQL Server 开发互联网之web应用!

iframe自适应高度计算,iframe自适应

计算页面的实际高度,iframe自适应会用到
IfrHeight: function (iframeId, callback) {
  var height;
  function calcPageHeight(doc) {
  var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight);
  var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight);
  height = Math.max(cHeight, sHeight);
  return height;
}

var ifr = document.getElementById(ifId);

setTimeout(function () {
  var iDoc = ifr.contentDocument || ifr.document;
  height = calcPageHeight(iDoc);
  ifr.style.height = height + 'px';
  callback(height);
  return height;
  }, 500);
},

posted on 2015-05-12 17:55  Seves2015  阅读(693)  评论(0编辑  收藏  举报

导航