Solved

dynamically resizing an iframe

Posted on 2011-02-16
3
265 Views
Last Modified: 2012-06-27
Hi Experts,

I have a webpage that contains an iframe that is restricted by the height/width of a parent div.

ie
<div class="mainframe" style="height:220px; width:196px">                
	<iframe class="myframe" src="login.php" scrolling="no" frameborder="0" width="100%" height="100%" >
	</iframe>
</div>  

Open in new window

The purpose of login.php is provide the user with a login form.
Within the form, there is a link for the user to register if they do not have a log in.
When they click register, I want the div to be resized to eg height:420px; width:296px
to accommodate the registration form.

How do I do this?

Thanks!
0
Comment
Question by:jagku
  • 2
3 Comments
 
LVL 15

Assisted Solution

by:Tomarse111
Tomarse111 earned 500 total points
ID: 34907707
First up stick an ID on your mainframe. Then add the script attached to your login.php ..

<div class="mainframe" id="mainframe" style="height:220px; width:196px">                
      <iframe class="myframe" src="test2.cfm" scrolling="no" frameborder="0" width="100%" height="100%" >
      </iframe>
</div>  
<script type="text/javascript">
	resize=function(){
		var div=parent.document.getElementById('mainframe')		
		div.style.height=500;
		div.style.width=500;		
	}
</script>
<body bgcolor="#FF0000">
<a href="javascript:void(0);" onclick="resize()">link</a>
</body>

Open in new window

0
 
LVL 15

Accepted Solution

by:
Tomarse111 earned 500 total points
ID: 34907723
Ok that was using my test data, this is using your data:

<div class="mainframe" id="mainframe" style="height:220px; width:196px">                
      <iframe class="myframe" src="login.php" scrolling="no" frameborder="0" width="100%" height="100%" >
      </iframe>
</div>  
<script type="text/javascript">
	resize=function(){
		var div=parent.document.getElementById('mainframe')		
		div.style.height=420;
		div.style.width=296;		
	}
</script>
<body bgcolor="#FF0000">
<a href="javascript:void(0);" onclick="resize()">link</a>
</body>

Open in new window

0
 

Author Closing Comment

by:jagku
ID: 34907911
Perfect!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

791 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