How to get length of document in an iframe

A

Asterbing

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 ?
 
A

Asterbing

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)...
 
T

The Magpie

Asterbing said:
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
<iframe> at 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.
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top