Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Iframe - width 100%, height 100%

Posted on 2011-03-03
13
Medium Priority
?
1,141 Views
Last Modified: 2012-08-13
Hi,
I am using iframes.
I think its know problem that you cant get the height and width to 100%?
Was just wondering if there is nay fix to it.
Can any please help me out with it, its killing my design

Thanks
0
Comment
Question by:SameerMirza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
13 Comments
 
LVL 14

Expert Comment

by:R-Byter
ID: 35027988
Is this what you are looking for:

http://th.atguy.com/mycode/100_percent_iframe/

Regards
0
 

Author Comment

by:SameerMirza
ID: 35028368
thanks for your help but it doesnt work in IE - using 6
havent tested in any other browser
Please have a look at the code below,
you would have to add any .pdf file insted of test.pdf


<html>
<head>
<link href='html\css\gtsportal.css' type='text/css' rel='stylesheet'>
<script language="JavaScript">
<!--
function resize_iframe()
{	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the
	//window (all these should be on the same line)
	document.getElementById("glu").style.height=parseInt(height-
	document.getElementById("glu").offsetTop-8)+"px";
}
// this will resize the iframe every
// time you change the size of the window.
window.onresize=resize_iframe; 
//Instead of using this you can use: 
//	<BODY onresize="resize_iframe()">

//-->
</script>
</head>
</body>
<IFRAME NAME="iframe1" id = "glu" src = 'test.pdf'  ALIGN="top" HSPACE="0" VSPACE="0"  frameborder="0"  width="100%" onload="resize_iframe();"></IFRAME>
</body>
</html>

Open in new window

0
 
LVL 14

Accepted Solution

by:
R-Byter earned 1500 total points
ID: 35029369
Here you go, I tested in various browsers and it works:

<html>
<head>
<link href='html\css\gtsportal.css' type='text/css' rel='stylesheet'>
<script language="JavaScript">
<!--
function resize_iframe()
{       
		var height=window.innerWidth;//Firefox
        if (document.body.clientHeight)
        {
                height=document.body.clientHeight;//IE
        }
        //resize the iframe according to the size of the
        //window (all these should be on the same line)
        document.getElementById("glu").style.height=parseInt(height-document.getElementById("glu").offsetTop-8)+"px";
		//quick fix for Friefox redirecting bug
		if (document.getElementById("glu").src=="")
		{
			document.getElementById("glu").src="test.pdf";
		}
}
// this will resize the iframe every
// time you change the size of the window.
//window.onresize=resize_iframe; 
//Instead of using this you can use: 
//      <BODY onresize="resize_iframe()">

//-->
</script>
</head>
<body>
<IFRAME NAME="iframe1" id="glu" width="100%" onload="resize_iframe()"></IFRAME>
</body>
</html>

Open in new window


Live example here:

http://www.bosko.rs/ee/iframew100h100/

Regards
0
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 

Author Comment

by:SameerMirza
ID: 35029696
thanks.
Havnt tested the code yet but in example you have to refresh the page to get it working.
0
 

Author Comment

by:SameerMirza
ID: 35029789
I am sorry but I have just tested the code in IE6 same result
0
 

Author Comment

by:SameerMirza
ID: 35029845
nither in IE 7. Sorry for another comment but just wanted to confirm.
0
 

Author Comment

by:SameerMirza
ID: 35030089
ok I am very sorry
problem is with pdf
It doesnt work with .pdf files.
Please have a look to confirm
try nay .pdf file as frame src.
0
 
LVL 14

Expert Comment

by:R-Byter
ID: 35034792
I tested solution posted as live example in my previous post:

http://www.bosko.rs/ee/iframew100h100/

It works in IE7, IE8, Firefox, Chrome, Opera and Safari.
Don't know what could be the problem at your side. Did You copy and paste my code?

Regards
0
 

Author Comment

by:SameerMirza
ID: 35036851
I have tried it and works but the porlbem is the spacing around the frame or padding in otherwords
so basically it leaves around 10px around it and place 6the iframe in the middle.
I have also tried,
html, body{
margin-top:0px;
margin-left:0px;
margin-right:0px;
padding: 0px 0px 0px 0px;
overflow: hidden;
background-color: #ffffff; }

doesnt help much
0
 
LVL 14

Expert Comment

by:R-Byter
ID: 35036893
Here you go, put this instead of <body>:

<body topmargin="0" leftmargin="0">

Open in new window


Be aware that I didnt use any css file since you didnt post it here.

Regards
0
 

Author Comment

by:SameerMirza
ID: 35037718
Well it doesnt work without one
I tried using ur code as it is
0
 

Author Comment

by:SameerMirza
ID: 35038036
it sems to work but still it leaves some space at the bottom. around 5 to 10px
0
 

Author Closing Comment

by:SameerMirza
ID: 35058104
It couldnt serve the purpose for me but I guess its alomost there.
I had to refresh it all the time to get it to work but may help some one
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn how to count occurrences of each item in an array.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question