space between top of browser or frame and document body 
September 12th, 2008, 06:45 PM
| | | |
Is there any way to control the space between top of browser or frame
and document body?
What I have is this: There is a simple file test1.html, and file
test.html that displays test1.html in an iframe. On the iframe I set
marginheight and marginwidth to zero. But there is one line of blank
space between the top border of the iframe and the first line of
text. However, the iframe's content document's body's offsetHeight
gives the height without considering this extra space between the top
margin of the iframe and the body. As a result, when I set the
iframe's height to the offsetHeight through Javascript, it is not big
enough but one line. This is on Mozilla 2.0.
test1.html ==>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test1</title>
</head>
<body>
<p>Here is some text. Here is some text. Here is some text. Here is
some text. Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text. Here is some
text. Here is some text. Here is some text. Here is some text. Here is
some text. Here is some text. Here is some text. Here is some text.
Here is some text. Here is some text. Here is some text. Here is some
text. END.</p>
</body>
</html>
test.html ==>
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<script type="text/javascript">
function changeFrameContents(newurl) {
var myframe = document.getElementById('myframe');
myframe.src = newurl;
}
</script>
<script type="text/javascript">
function myframeFullHeight() {
var frame = document.getElementById('myframe'); // iframe
var frameContent = frame.contentDocument;
var frameContentBody = frameContent.getElementsByTagName("body")
[0];
var height = frameContentBody.offsetHeight;
alert(height);
frame.height = height;
}
</script>
</head>
<body>
<h1>Heading</h1>
<iframe id="myframe" frameborder="1" scrolling="no"
marginheight="-10" marginwidth="0" src="test1.html"
style="display:block; margin-bottom:3em" onload="myframeFullHeight()">
</iframe>
<input type="button" value="test1"
onclick="changeFrameContents('test1.html');" />
<input type="button" value="test2"
onclick="changeFrameContents('test2.html');" />
<p/>
<input id="myinput" type="text" size="10" maxlength="10"
style="display:block"/>
<input type="button" value="resize" onclick="myframeFullHeight()"/>
</body>
</html> | 
September 12th, 2008, 06:55 PM
| | | | re: space between top of browser or frame and document body removeps-groups@yahoo.com wrote: Quote:
Is there any way to control the space between top of browser or frame
and document body?
>
What I have is this: There is a simple file test1.html, and file
test.html that displays test1.html in an iframe. On the iframe I set
marginheight and marginwidth to zero. But there is one line of blank
space between the top border of the iframe and the first line of
text. However, the iframe's content document's body's offsetHeight
gives the height without considering this extra space between the top
margin of the iframe and the body. As a result, when I set the
iframe's height to the offsetHeight through Javascript, it is not big
enough but one line. This is on Mozilla 2.0.
| body { margin: 0; padding: 0; }
? | 
September 12th, 2008, 11:45 PM
| | | | re: space between top of browser or frame and document body
On Sep 12, 10:54 am, Harlan Messinger
<hmessinger.removet...@comcast.netwrote: Quote: |
body { margin: 0; padding: 0; }
| Did not work. In my file test1.html I tried both
<body style="margin: 0; padding: 0;">
and
<style type="text/css">
body { margin: 0; padding: 0; }
</style> | 
September 13th, 2008, 10:45 AM
| | | | re: space between top of browser or frame and document body
On 2008-09-12, removeps-groups@yahoo.com <removeps-groups@yahoo.comwrote: Quote:
On Sep 12, 10:54 am, Harlan Messinger
><hmessinger.removet...@comcast.netwrote:
> Quote: |
> body { margin: 0; padding: 0; }
| >
Did not work. In my file test1.html I tried both
>
><body style="margin: 0; padding: 0;">
>
and
>
<style type="text/css">
body { margin: 0; padding: 0; }
</style>
| I supposed you could try
html, body { margin: 0; padding: 0 } | 
September 15th, 2008, 10:55 PM
| | | | re: space between top of browser or frame and document body
On Sep 13, 2:38 am, Ben C <spams...@spam.eggswrote: Quote:
I supposed you could try
>
html, body { margin: 0; padding: 0 }
| Still didn't work. Maybe the workaround is to add 64 to the offset
height, for example:
var height = frameContentBody.offsetHeight + 64;
frame.height = height; | 
September 16th, 2008, 12:05 AM
| | | | re: space between top of browser or frame and document body
On Sep 15, 2:46 pm, "removeps-gro...@yahoo.com" <removeps-
gro...@yahoo.comwrote: Quote:
On Sep 13, 2:38 am, Ben C <spams...@spam.eggswrote:
>> Quote: |
html, body { margin: 0; padding: 0 }
| >
Still didn't work. Maybe the workaround is to add 64 to the offset
height, for example:
>
var height = frameContentBody.offsetHeight + 64;
frame.height = height;
| Strange, when the child document, which in my case is test1.html, has
the DOCTYPE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
then the value of
var height = frame.contentWindow.document.body.scrollHeight + "px";
is 200. So after setting iframe.style.height = height, there is still
a vertical scrollbar because the vertical space is not big enough.
But if I remove the DOCTYPE, then the height is 216. There is no
vertical scrollbar. Most strange indeed!
Note that in either case -- with or without the DOCTYPE -- the value
of height is 200px when calculating it using the following method
var frameContent = frame.contentDocument;
var frameContentBody = frameContent.getElementsByTagName("body")
[0];
var height = frameContentBody.offsetHeight;
Now if my child document has no DOCTYPE, it cannot be validated, so
maybe I can add a DOCTYPE, validate it, then remove the DOCTYPE | 
September 16th, 2008, 01:45 PM
| | | | re: space between top of browser or frame and document body
In article
<af570c89-8270-449e-a056-03040bf12d59@s20g2000prd.googlegroups.com>,
"removeps-groups@yahoo.com" <removeps-groups@yahoo.comwrote: Quote:
On Sep 15, 2:46 pm, "removeps-gro...@yahoo.com" <removeps-
gro...@yahoo.comwrote: Quote:
On Sep 13, 2:38 am, Ben C <spams...@spam.eggswrote: Quote: |
html, body { margin: 0; padding: 0 }
| Still didn't work. Maybe the workaround is to add 64 to the offset
height, for example:
var height = frameContentBody.offsetHeight + 64;
frame.height = height;
| >
Strange, when the child document, which in my case is test1.html, has
the DOCTYPE
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
then the value of
>
var height = frame.contentWindow.document.body.scrollHeight + "px";
>
is 200. So after setting iframe.style.height = height, there is still
a vertical scrollbar because the vertical space is not big enough.
>
But if I remove the DOCTYPE, then the height is 216. There is no
vertical scrollbar. Most strange indeed!
| Just out of curiosity, what happens if you use the HTML 4 Strict
DocType instead? There has been much discussion here in the past
about why XHTML 1.0 Transitional should be avoided; I'd be interested
to know if this is yet another reason. | 
September 16th, 2008, 10:45 PM
| | | | re: space between top of browser or frame and document body
On Sep 16, 5:26 am, David Stone <no.em...@domain.invalidwrote: Quote: |
<af570c89-8270-449e-a056-03040bf12...@s20g2000prd.googlegroups.com>,
| Quote: Quote:
But if I remove the DOCTYPE, then the height is 216. There is no
vertical scrollbar. Most strange indeed!
| | Quote:
Just out of curiosity, what happens if you use the HTML 4 Strict
DocType instead? There has been much discussion here in the past
about why XHTML 1.0 Transitional should be avoided; I'd be interested
to know if this is yet another reason.
| WIth all the following 6 DOCTYPES the height is 200px.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://
www.w3.org/TR/html4/frameset.dtd">
Only with no DOCTYPE is the height of the iframe 216px, which means no
vertical scrollbar.
But I ran into a problem with iframe. When I click a hyperlink in the
iframe, the browser appears to send a request to both the parent and
iframe. That is, when clicking a hyperlink in the iframe which is
test1.jsp, the server processes the parent page test.jsp again as well
as the frame test1.jsp. This is a problem for me as it means that JSF
bindings in the test.jsp page would get processed, and the page is
unnecessarily built. So I may use a div with AJAX instead, instead of
iframes. | 
September 17th, 2008, 04:15 PM
| | | | re: space between top of browser or frame and document body
In article
<5f72a3ef-2f88-41ab-aa6e-90b5d9a015ab@25g2000prz.googlegroups.com>,
"removeps-groups@yahoo.com" <removeps-groups@yahoo.comwrote: Quote:
On Sep 16, 5:26 am, David Stone <no.em...@domain.invalidwrote: Quote: |
<af570c89-8270-449e-a056-03040bf12...@s20g2000prd.googlegroups.com>,
| > Quote: Quote:
But if I remove the DOCTYPE, then the height is 216. There is no
vertical scrollbar. Most strange indeed!
| | > Quote:
Just out of curiosity, what happens if you use the HTML 4 Strict
DocType instead? There has been much discussion here in the past
about why XHTML 1.0 Transitional should be avoided; I'd be interested
to know if this is yet another reason.
| >
WIth all the following 6 DOCTYPES the height is 200px.
>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://
www.w3.org/TR/html4/frameset.dtd">
| Did the page validate using the W3C validator? Odd effects are likely
to occur if there is some problem with either the html or css
according to the started doctype etc. Quote:
>
Only with no DOCTYPE is the height of the iframe 216px, which means no
vertical scrollbar.
>
But I ran into a problem with iframe. When I click a hyperlink in the
iframe, the browser appears to send a request to both the parent and
iframe. That is, when clicking a hyperlink in the iframe which is
test1.jsp, the server processes the parent page test.jsp again as well
as the frame test1.jsp. This is a problem for me as it means that JSF
bindings in the test.jsp page would get processed, and the page is
unnecessarily built. So I may use a div with AJAX instead, instead of
iframes.
| I was intrigued by a comment in the html spec, just after iframe,
which mentioned using <objectto embed one html file inside another.
I wonder if this would work better for you? |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|