Wednesday, April 17, 2013

Fit Iframe to Screen Size

My HTML page body looks like below.

<div id="wrapper">
<div id="top-contact"><img src="" width="232" height="59" alt="Contac No" /></div>
<div id="top-menu"> &nbsp; <a href="landing.aspx">Landing </a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;<a href="OnTimeLearning.aspx">Learn OnTime</a>&nbsp;&nbsp;&nbsp;|
<iframe src="" width="100%" class="myIframe"></iframe>
<div id="fotter-ontime">© 2013 RED ROCK Software Solutions</div>

I have two div tags for the header and the footer in between i have the iframe. Now we need to set the iframe size to fit any screen size.

Using Jquery i'm going to reduce the heights of the two div tags on the header and footer and the width ratio is set to 100%.

<script type="text/javascript" src="Scripts/jquery-1.8.3.js"></script>
<script language="javascript">
$(document).ready(function () {
var height = $(window).outerHeight() - ($("#top-menu").outerHeight() + $("#fotter-ontime").outerHeight());
$('.myIframe').css('height', height + 'px');

No comments:
Write comments
Recommended Posts × +