By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,694 Members | 1,845 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,694 IT Pros & Developers. It's quick & easy.

Resizing an IFrame

P: n/a
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>
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"H.A.P" <ha***@hotmail.com> wrote in message
news:bk************@ID-51430.news.uni-berlin.de...
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

Jul 20 '05 #2

P: n/a
"H.A.P" <ha***@hotmail.com> writes:
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:
<script type="text/javascript">
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.