469,275 Members | 1,628 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

Text Not Being Displayed

Hi,
I've been trying for some time now to get the height (the 'scrollable'
height) of the current page (Thanks to Martin Honnen for help so far). I
feel as though I am almost there, but am having an unusual problem. (Please
see the code at the end of this page.)

The text "This text isn't being displayed" isn't, as you might have guessed,
being displayed.

I can't seem to display any 'normal' content unless I include it in the
<script>.

Why?

Why, why why?

Hope you can help,

Paul

----------

<html>
<head>
<title>Display Page Height</title>
<SCRIPT TYPE="text/javascript">
<!--
function pageHeight()
{
docHeight = 0;
if (typeof document.height != 'undefined')
{
docHeight = document.height;
}
else if (document.compatMode && document.compatMode != 'BackCompat')
{
docHeight = document.documentElement.scrollHeight;
}
else if (document.body && typeof document.body.scrollHeight != 'undefined')
{
docHeight = document.body.scrollHeight;
}
writeHeight(docHeight);
}
window.onload = pageHeight;
//-->
</SCRIPT>
</head>
<body>
<p>This text isn't being displayed!</p>
<SCRIPT TYPE="text/javascript">
<!--
function writeHeight(height)
{
document.write("Document has a height of " + height);
}
//-->
</SCRIPT>
</body>
</html>
Jul 20 '05 #1
6 1744
Paul wrote:
Hi,
I've been trying for some time now to get the height (the
'scrollable' height) of the current page (Thanks to Martin Honnen for
help so far). I feel as though I am almost there, but am having an
unusual problem. (Please see the code at the end of this page.)

The text "This text isn't being displayed" isn't, as you might have
guessed, being displayed.


well, it actually is displayed under Opera 7.21 but if and only if you
remove the script:

<SCRIPT TYPE="text/javascript">
<!--
function writeHeight(height)
{
document.write("Document has a height of " + height);
}
//-->
</SCRIPT>
Jul 20 '05 #2
> The text "This text isn't being displayed" isn't, as you might have
guessed,
being displayed.
It *is* being displayed, just not for very long.
Why?
Do a 'View source' on the page and you may see what has happened.
Why, why why?


When you call document.write after the page has been parsed you are
overwriting the page, not appending to it.
Jul 20 '05 #3
"karambol" <ka******@euro26.org.pl> wrote in message
news:3f******@news.vogel.pl...
Paul wrote:
Hi,
I've been trying for some time now to get the height (the
'scrollable' height) of the current page (Thanks to Martin Honnen for
help so far). I feel as though I am almost there, but am having an
unusual problem. (Please see the code at the end of this page.)

The text "This text isn't being displayed" isn't, as you might have
guessed, being displayed.


well, it actually is displayed under Opera 7.21 but if and only if you
remove the script:

<SCRIPT TYPE="text/javascript">
<!--
function writeHeight(height)
{
document.write("Document has a height of " + height);
}
//-->
</SCRIPT>


So, If I remove the functionality of the script, I can display basic HTML?

Anyone got any real suggestions?
Jul 20 '05 #4
"Graham J" <in***************@orangebucket.co.uk> wrote in message
news:bn*************@ID-203032.news.uni-berlin.de...
The text "This text isn't being displayed" isn't, as you might have

guessed,
being displayed.


It *is* being displayed, just not for very long.
Why?


Do a 'View source' on the page and you may see what has happened.
Why, why why?


When you call document.write after the page has been parsed you are
overwriting the page, not appending to it.


Ah, I see - thanks.

Now the problem has been identified, I need a solution!

Is there anyway to append to the page rather than overwrite it entirely?

Thanks for you help - I'm very grateful,

Paul
Jul 20 '05 #5
> Ah, I see - thanks.

Now the problem has been identified, I need a solution!

Is there anyway to append to the page rather than overwrite it

entirely?

Well I don't know exactly what you are trying to achieve so it might
be that you can do what you want just by triggering scripts at the
bottom of your markup before the </body> when just about everything is
in place but the page hasn't finished loading. However whatever you
are trying to do requires the page to have been fully loaded then you
have to work with the elements you have on the page already. You
probably need to read up on 'innerHTML'. For example you could have
an empty <div> at the end of the page and write content into that.

Jul 20 '05 #6
Anyone got any real suggestions?


Here's your "REAL" suggestion. and a solution too.

All you've got to do is to create a block of text (may be <p>, nay be
div, doesn't matter) give it an id and then change it's innerHTML in
the script. this works for IE and Opera, but i don't think it will for
mozilla, so keep searching.

<html>
<head>
<title>Display Page Height</title>
<SCRIPT TYPE="text/javascript">
<!--
function pageHeight()
{
docHeight = 0;
if (typeof document.height != 'undefined')
{
docHeight = document.height;
}
else if (document.compatMode && document.compatMode != 'BackCompat')
{
docHeight = document.documentElement.scrollHeight;
}
else if (document.body && typeof document.body.scrollHeight !=
'undefined')
{
docHeight = document.body.scrollHeight;
}
writeHeight(docHeight);
}
window.onload = pageHeight;
//-->
</SCRIPT>
</head>
<body>
<p>This text isn't being displayed!</p>
<p id="foo"></p>
<SCRIPT TYPE="text/javascript">
<!--
function writeHeight(height)
{
document.all('foo').innerHTML = "Document has a height of " + height;
}
//-->
</SCRIPT>
</body>
</html>
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stefan De Schepper | last post: by
reply views Thread by Krzysztof Fink-Finowicki via .NET 247 | last post: by
7 posts views Thread by Matt | last post: by
3 posts views Thread by Rigga | last post: by
4 posts views Thread by Mark L. Breen | last post: by
11 posts views Thread by Chris Ianson | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.