Resizing an IFrame

H

H.A.P

hi

I'm trying to change the size of an iframe. In the following page, how
should I do it?

<html>

<head>
<script language="javascript">
function resize_frm() {
I1.width=400;
}
</script>
</head>

<body>
<p onclick="resize_frm()">RESIZE</p>

<iframe name="I1" src="contents.htm" width="200" height="150">
Your browser does not support inline frames or is currently configured not
to display inline frames.</iframe>

</body>

</html>
 
V

Vjekoslav Begovic

H.A.P said:
hi

I'm trying to change the size of an iframe. In the following page, how
should I do it?

<html>

<head>
<script language="javascript">
function resize_frm() {
I1.width=400;
}
</script>
</head>

<body>
<p onclick="resize_frm()">RESIZE</p>

<iframe name="I1" src="contents.htm" width="200" height="150">
Your browser does not support inline frames or is currently configured not
to display inline frames.</iframe>

</body>

</html>

If you have an inline frame with id:

<iframe id="I1" src="contents.htm" width="200" height="150">

than you could write:

document.getElementById("I1").width = 400
 
L

Lasse Reichstein Nielsen

H.A.P said:
I'm trying to change the size of an iframe. In the following page, how
should I do it?
<script language="javascript"
The type attribute is required, and language is deprecated:
function resize_frm() {
I1.width=400;

You shouldn't access named elements as properties of the global object.
Few browsers allow that (although one of them is used quite a lot).

Either
var iframe = document.getElementsByTagName("iframe")[0];
or give the iframe an id and use document.getElementById.

To change the width, use style.width:
iframe.style.width = "400px";
Remember the unit, it is required in CSS.
<iframe name="I1" src="contents.htm" width="200" height="150">

Don't use the width and height attributes, but use CSS instead:
<iframe name="I1" id="iframe1Id" src="contents.htm"
style="width:200px;height:150px;">

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top