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

How to get length of document in an iframe

P: n/a
I want to know the length in pixels of a document embedded in a iframe.
The way I go seems to work under IE but not under Firefox (about other
browsers I'll see later).

Here is my page for testing :

1) The page which will appear in the iframe is :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>inside</title>
<script type="text/javascript">
function docsize(){
alert(this.document.body.scrollHeight + "px");}
</script>
</head>
<body bgcolor="white">
<form action="" method="post">
<input type="button" value="Size of Doc Inside" onclick="docsize();">
</form>
<p>ljlsqdjqlsd ljsqldjqs dlj lqsjkd lqsdkj lqskdjsq ldqsdlj lqsdkj
qslkdj ql qsldjqs dlqs jdlqs dlqsdj qsldj qsl dqlsd sqld jsqld qsdqsl
dlqs dqsl dlqs dlqs dlqsjd lqsd qsld qsdl qsdlqsj dlqsjd sqld qsld lsqd
lqzd qsld qsldjqs dlqs dlqs dlqs dlqs dlqsd qsl dqs dlqsd qsld qsld qsld
qsld qsld qsld qsl dsqld qsl dlqs dqsj dlqsd sqld qsld qsld qsljd qsldj
qsld qsld jqsld qsld jqsl dqsjld qsld jqsl dsql djqsld jqsld qsld qsld
qsl djqsld qsld qsldjqs ldj qsdl
<br><br>
That's all !</p>
</body>
</html>

2) The document with the iframe which will contains the first doc

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>iFrame resize</title>
<script type="text/javascript">
function resize(h)
{
var f = document.getElementById("container");
f.setAttribute("height", h);
}
</script>
</head>
<body style="background: purple">
<form action="" method="post">
<input type="button" value="500" onclick="resize(500);">
<input type="button" value="250" onclick="resize(250);">
</form>
<div style="position: absolute; visibility: visible; border: dotted
white">
<iframe id="container" width="731" height="100" src="some.htm"
scrolling="no" style="border: thin"></iframe></div>
</body>
</html>
So, to test, just do this :
1) clic to knwow current size
2) clic to resize the iframe
3) the size of doc inside shouldn't change with iframe size (I don't
want the iframe size, but the size of document inside)

It works under IE, not Firefox 1.5 under Windows

How to do it works ?
Jun 14 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <MP************************@news.tiscali.fr>, no@thanks.com
says...
I want to know the length in pixels of a document embedded in a iframe.
The way I go seems to work under IE but not under Firefox (about other
browsers I'll see later).

Here is my page for testing :

1) The page which will appear in the iframe is :

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>inside</title>
<script type="text/javascript">
function docsize(){
alert(this.document.body.scrollHeight + "px");}
</script>
</head>
OK, I've changed the scrollHeight with offsetHeight and it works for
Firefox 1.5 (not tested in 2.0 : if someone can tel me)

So, now, I would like it works for Netscape and Mozilla. So, I've tried
with "this.document.documentElement.scrollHeight", but I fall down in
same problem as the was I had with Firefox.

So, what's the good expression for Netscape and its derivated browsers ?

After I will wish to know for the browsers used under Linux : Konqueror
and others you'll tell me (I don't use Linux)...
Jun 14 '07 #2

P: n/a
Asterbing wrote:
>
OK, I've changed the scrollHeight with offsetHeight and it works for
Firefox 1.5 (not tested in 2.0 : if someone can tel me)
Purely personally, my first port of call would have been to not use an
<iframeat all. It isn't really needed anyway and I have to say I
simply could not see why you had gone that route at all.
Jun 15 '07 #3

P: n/a
Asterbing wrote:
OK, I've changed the scrollHeight with offsetHeight and it works
for Firefox 1.5 (not tested in 2.0 : if someone can tel me)
"The Magpie" <us****@pigsinspace.co.ukwrote:
: Purely personally, my first port of call would have been to not use
: an <iframeat all. It isn't really needed anyway and I have to say
: I simply could not see why you had gone that route at all.

Two questions:
(1) How would you do it?
(2) If you did go the iframe route, how would you do it?

--
Jim Carlock
Custom Swimming Pool Designers
http://www.aquaticcreationsnc.com/sw...c/viewing1.php
Jun 27 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.