Connecting Tech Pros Worldwide Help | Site Map

space between top of browser or frame and document body

  #1  
Old September 12th, 2008, 06:45 PM
removeps-groups@yahoo.com
Guest
 
Posts: n/a
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>
  #2  
Old September 12th, 2008, 06:55 PM
Harlan Messinger
Guest
 
Posts: n/a

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; }

?
  #3  
Old September 12th, 2008, 11:45 PM
removeps-groups@yahoo.com
Guest
 
Posts: n/a

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>

  #4  
Old September 13th, 2008, 10:45 AM
Ben C
Guest
 
Posts: n/a

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 }
  #5  
Old September 15th, 2008, 10:55 PM
removeps-groups@yahoo.com
Guest
 
Posts: n/a

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;

  #6  
Old September 16th, 2008, 12:05 AM
removeps-groups@yahoo.com
Guest
 
Posts: n/a

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:
I supposed you could try
>
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
  #7  
Old September 16th, 2008, 01:45 PM
David Stone
Guest
 
Posts: n/a

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:
I supposed you could try
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.
  #8  
Old September 16th, 2008, 10:45 PM
removeps-groups@yahoo.com
Guest
 
Posts: n/a

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.
  #9  
Old September 17th, 2008, 04:15 PM
David Stone
Guest
 
Posts: n/a

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?
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top Drop Down Menu for IE that can overlay IE combo box and has fading effect Yuk Cheng answers 4 July 23rd, 2005 01:18 PM
DHTML Menu change target frame RWD answers 2 July 23rd, 2005 12:45 PM
slide menu how to make it relative to table ajay answers 1 July 20th, 2005 07:54 PM