Document.write headaches

A

Adam

Hey gang,

I'm trying to have a certain piece of html be written into a document
depending on the browser (specifically, Netscape). Anyway, I have the
following INSIDE the html (nested in a table) and wonder if this is
incorrect. Can someone give me some pointers? It's been a while since
I've done any javascripting and this will help so much. Thank you!!

<script language="javascript">
<!-- hide javascript
if (navigator.appName == 'Netscape'){
document.write('<TD align=center height=250><img
src=media/copyright.gif width=260 height=13 alt= border=0>';
}

else {
document.write('<TD align=center><img src=media/copyright.gif
width=260 height=13 alt= border=0>';
}
// done hiding -->
</SCRIPT>
 
L

Lasse Reichstein Nielsen

Evertjan. said:
<SCRIPT>

document.write() needs a closing bracked:

I think that is the original posters problem.
===================

why not do this:

<TD align="center"
<SCRIPT>
if (navigator.appName == 'Netscape')
document.write("height="250px")
</SCRIPT>

Because it is illegal HTML. Script tags are HTML tags, and they must
obey the normal rules for nesting tags. You cannot put a tag *inside*
another tag, only inside the element (between open and close tags).
(And as a side note, script tags are only legal inside the head or
body elements).

Also, you shouldn't add "px" to the height attribute. Preferably you
shouldn't use the HTML height attribute, but use CSS styles instead
(as you say later), or you should just write the number (height="250").
<TD align="center" id="td74">
<img src="media/copyright.gif" width="260px"
height="13px" alt="" border="0">

and later [or <body onload=..]

<SCRIPT>

Type is mandatoty.
if (navigator.appName == 'Netscape')
document.getElementById("td74").height="250px"

The original poster didn't say which Netscape he is after, and this
would break in Netscape 4. Apart from that, I would prefer this
method. The HTML height attribute doesn't use "px".
btw1: it seems more reasonable to set the height of a <tr> than of a <td>

It should work, at least if you use CSS (I am not sure how the HTML
attributes interact with CSS, but proabably reasonably).
The height of a table cell is the maximum of the specified height and what
the contents need. The height of a table row is the maximum of its specified
height and the heights of the cells in that row.
btw2: even better use css:

Absolutely!

/L
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top