2012-12-01 149 views
1

想要獲取div並查找iframe標記,並查看它是否具有寬度和高度,如果是,請將它們更改爲我給出的數字,如果不是,則將寬度和高度添加到iframe。調整iframe的大小

<div class="player container"> 

    <iframe width="1280" height="720" src="http://www.youtube.com/"</iframe> 

</div> 

我只是不知道該怎麼做,如果你能幫助我,這將是我的榮幸。 感謝

回答

0

試試這個使用Javascript: - 。

<script type=&#34;text/javascript&#34;> 
<!--// 
    function sizeFrame&#40;frameId&#41; { 
    var F = document.getElementById&#40;frameId&#41;; 
    if&#40;F.contentDocument&#41; { 
    F.height = F.contentDocument.documentElement.scrollHeight+30; //FF 3.0.11, Opera 9.63, and Chrome 
} else { 

F.height = F.contentWindow.document.body.scrollHeight+30; //IE6, IE7 and Chrome 

} 

} 

window.onload=sizeFrame; 

//--> 
</script> 

<iframe width=&#34;100%&#34; id=&#34;myFrame&#34; src=&#34;testincludegallery.php?id=1&#34; scrolling=&#34;no&#34; frameborder=&#34;0&#34; onload=&#34;window.parent.sizeFrame&#40;&#39;myFrame&#39;&#41;;&#34;> 
+0

我有此代碼,但我不工作,VAR IFRAME = $( 「div.player」)找到( 「IFRAME」 ); \t \t iframe.addClass('container'); –

0
var iframe = $("div").find("iframe"); 
var w = iframe.width(); 
var h = iframe.height(); 

iframe.attr('width', (w)?w+num:num); 
iframe.attr('height', (h)?h+num:num);