Document.write headaches

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam

    Document.write headaches

    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="javas cript">
    <!-- hide javascript
    if (navigator.appN ame == '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><i mg src=media/copyright.gif
    width=260 height=13 alt= border=0>';
    }
    // done hiding -->
    </SCRIPT>
  • Lasse Reichstein Nielsen

    #2
    Re: Document.write headaches

    "Evertjan." <exjxw.hannivoo rt@interxnl.net > writes:
    [color=blue]
    > <SCRIPT>[/color]

    <script type="text/javascript">
    The type attribute is mandatory in HTML 4+
    [color=blue]
    > document.write( ) needs a closing bracked:[/color]

    I think that is the original posters problem.
    [color=blue]
    > =============== ====
    >
    > why not do this:
    >
    > <TD align="center"
    > <SCRIPT>
    > if (navigator.appN ame == 'Netscape')
    > document.write( "height="250px" )
    > </SCRIPT>[/color]

    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").
    [color=blue]
    > <TD align="center" id="td74">
    > <img src="media/copyright.gif" width="260px"
    > height="13px" alt="" border="0">
    >
    > and later [or <body onload=..]
    >
    > <SCRIPT>[/color]

    Type is mandatoty.
    [color=blue]
    > if (navigator.appN ame == 'Netscape')
    > document.getEle mentById("td74" ).height="250px "[/color]

    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".
    [color=blue]
    > btw1: it seems more reasonable to set the height of a <tr> than of a <td>[/color]

    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.
    [color=blue]
    > btw2: even better use css:[/color]

    Absolutely!

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Evertjan.

      #3
      Re: Document.write headaches

      Lasse Reichstein Nielsen wrote on 20 aug 2003 in comp.lang.javas cript:[color=blue]
      > Because it is illegal HTML.[/color]

      You are right. My brain was in serverside mode.

      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      Working...