Text Not Being Displayed

K

karambol

Paul said:
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>
 
P

Paul

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>
 
G

Graham J

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.

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.
 
P

Paul

karambol said:
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?
 
P

Paul

Graham J said:
It *is* being displayed, just not for very long.


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


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
 
G

Graham J

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.
 
K

karambol

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>
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top