Solved

Iframe - width 100%, height 100%

Posted on 2011-03-03
13
1,136 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 500 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Anyone familiar with PhotoSwipe? 3 40
Word Press Fixes to Google Speed Test Issues 2 50
iframe stay to the left of page 5 29
How do I buy BitCoin? 4 25
Find out what you should include to make the best professional email signature for your organization.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

737 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