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 >
  2. </iframe>
  1. window.onload = function(){
  2.      adjustIframe("js_sub_web");
  3. }

相关文章: