2011-12-24 55 views
3

私はstackoverflowで見つかったjavascriptのサイズ変更機能を使用していて、IEとFFでうまく機能します。しかし、Google Chromeでは、前のサイズよりも大きいiframeのサイズ変更しかできません。小さなiframeのサイズを変更する必要がある場合は、同じ高さで30pxを追加します。Google ChromeでJavascriptのリサイズ機能が動作しない

私はそれがscrollHeightを取得することと関連があると仮定しますが、それを修正する方法はわかりません。

私はすでにタイムアウトを使用しようとしましたが、それは助けてくれるかもしれない場所を読んだのでですが、そうではありません。

ここに関連するコードです:

function autoResize(id){ 
     var newheight; 
     if(document.getElementById) 
     { 
      newheight=document.getElementById(id).contentWindow.document.body.scrollHeight; 
      newheight=newheight+30; 
     } 
     document.getElementById(id).height = (newheight) + "px"; 
    } 

    <iframe src="<?php echo "$LC"; ?>/home.html" name="iframe" id="iframe" width="435px" height="10px" scrolling="no" frameborder="0" style="margin-left:-10px;padding-bottom:20px;" onLoad="setTimeout(autoResize('iframe'),250);";"> 

編集:答えとしてあなたの答えを追加してください

function autoResize(id) { 
     document.getElementById(id).height = document.getElementById(id).contentDocument.documentElement.scrollHeight+15; //Chrome 

     document.getElementById(id).height = document.getElementById(id).contentWindow.document.body.scrollHeight+15; //FF, IE 
    } 
+0

に機能を変更することによってそれを解決 - あなた自身に答える、その推奨される方法は、質問。 –

答えて

7
function autoResize(id) { 
    document.getElementById(id).height = document.getElementById(id).contentDocument.documentElement.scrollHeight+15; //Chrome 

    document.getElementById(id).height = document.getElementById(id).contentWindow.document.body.scrollHeight+15; //FF, IE 
} 
+2

if/elseブロックはjQuery.browserを使用して適用できます – Mehmed

関連する問題