首页 > 其他 > 详细

iframe自适应高度代码

时间:2015-04-17 11:14:18      阅读:109      评论:0      收藏:0      [点我收藏+]
  1. var adjustIframe = function (id) {
  2.     var iframe = document.getElementById(id)
  3.     var idoc = iframe.contentWindow && iframe.contentWindow.document || iframe.contentDocument;
  4.     var callback = function () {
  5.         var iheight = Math.max(idoc.body.scrollHeight, idoc.documentElement.scrollHeight); //取得其高
  6.         iframe.style.height = iheight + "px";
  7.     }
  8.     if (iframe.attachEvent) {
  9.         iframe.attachEvent("onload", callback);
  10.     } else {
  11.         iframe.onload = callback
  12.     }
  13. }

 

  1. <iframe id="js_sub_web" width="80%" frameborder="0" scrolling="no" allowTransparency="true" src="http://www.cnblogs.com/rubylouvre/archive/2009/09/15/1566722.html">
  2. </iframe>
  1. window.onload = function(){
  2.      adjustIframe("js_sub_web");
  3. }

iframe自适应高度代码

原文:http://www.cnblogs.com/goodbeypeterpan/p/4434175.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!