documnet.write

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

    #1

    documnet.write

    Hi,
    I don't know all the ins and outs of javascript so I don't know
    if there is something simple i am missing. Why will this code
    not display the browser width while the later will?

    this does not work
    <script language="JavaS cript1.2"><!--

    if (document.all)
    document.write( document.body.c lientWidth)

    //-->
    </script>

    This does work
    <script language="JavaS cript1.2"><!--

    document.write( "width=")
    if (document.all)
    document.write( document.body.c lientWidth)

    //-->
    </script>


    Obviously the browser has to pass my if statement, but I don't see
    what the problem is if the bottom works in my browsers. win IE6 and Firefox1

    Chuck
  • VK

    #2
    Re: documnet.write

    > this does not work[color=blue]
    > <script language="JavaS cript1.2"><!--
    >
    > if (document.all)
    > document.write( document.body.c lientWidth)
    >
    > //-->
    > </script>[/color]

    This works OK on IE 6

    Firefox doesn't support document.all collection, so your "if" branch is
    never executed.

    Try this instead (with some more respect to the language syntacs):
    ....
    if (document.all) {
    document.write( document.body.c lientWidth);
    }
    else if (document.getEl ementById) {
    document.write( document.width) ;
    }
    else {
    document.write( 'Hey, get yourself a normal browser!');
    }

    Where are some tiny difference in clientWidth and width from browser to
    browser, so you may need to manually adjust results (width+/-delta)


    Comment

    • Michael Winter

      #3
      Re: documnet.write

      On Mon, 25 Oct 2004 13:55:04 +0200, VK <schools_ring@y ahoo.com> wrote:
      [color=blue][color=green]
      >> this does not work
      >> <script language="JavaS cript1.2">[/color][/color]

      The language attribute has been deprecated in favour of the (required)
      type attribute for over five years. Moreover, specifying the language
      variant as 1.2 is positively dangerous and should always be avoided unless
      you explicitly want to invoke 1.2 parsing rules (and you don't - trust me).
      [color=blue][color=green]
      >> <!--[/color][/color]

      Similarly, hiding script contents is an out-dated practice that shouldn't
      be continued any more. All browsers currently in use understand what a
      SCRIPT element is, even if they have no intention of executing the
      contents. If you really need to prevent a user agent from reading the
      script, move it into an external file.
      [color=blue][color=green]
      >> if (document.all)
      >> document.write( document.body.c lientWidth)[/color][/color]

      [snip]
      [color=blue]
      > if (document.all) {
      > document.write( document.body.c lientWidth);
      > }
      > else if (document.getEl ementById) {
      > document.write( document.width) ;
      > }
      > else {
      > document.write( 'Hey, get yourself a normal browser!');[/color]

      What a helpful message.
      [color=blue]
      > }[/color]

      I don't see what the tests presented by you or the OP have to with what
      you're trying to accomplish. What bearing does support of document.all or
      document.getEle mentById have on the ability to find browser dimensions?

      A cross-browser solution has been presented by Richard Cornford in another
      thread
      (<URL:http://groups.google.c om/groups?threadm= 35742ecc.040909 1231.6b4fb829%4 0posting.google .com>).
      Note the correction later in that thread.

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail.

      Comment

      • VK

        #4
        Re: documnet.write

        > The language attribute has been deprecated in favour of the (required)[color=blue]
        > type attribute for over five years.[/color]

        Actually I did not touch this part of the OP's posting. If we started on it
        then:

        1.
        A language indication in any form was needed only for a short period of time
        between IE 3.0 - IE 3.02
        At that time IE tried to interpret any script (unless "JavaScript " is
        specified) as its newly introduced VBScript code. Sometimes it produced
        *funny* results. In IE 3.02 they (besides adding input-file) fixed IE's
        brains, and it never was an issue anymore.
        Any other browsers never used anything but JavaScript, so for them it was
        not an issue from the very beginning.
        As of 2004 A.D. <script></script> is enough, any extra would be a useless
        "white noise".

        2.
        <!-- // --> is still suggested: to hide inline scripts from webbots. They
        got much smarter over the last ten years, so you don't see too often index
        like:
        "My Home Page"
        var i = 1; var b = "";...
        myhomepage.com >

        Still it is better to be safe than sorry.

        3.[color=blue]
        > A cross-browser solution has been presented
        > by Richard Cornford in another thread[/color]

        This is a reputable name, and I'm sure in the quality of his code. But I
        think that the OP wanted to have HER code to work, not Mr. Cornford's one.
        And it's good - look how much extra info she got (if she took time to read
        our postings of course :-) - and how much would she miss by copy-paste 3rd
        party code, however perfect it is.


        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: documnet.write

          "VK" <schools_ring@y ahoo.com> writes:
          [color=blue]
          > As of 2004 A.D. <script></script> is enough, any extra would be a useless
          > "white noise".[/color]

          However, adding a "type" attribute would make it valid HTML, which some
          people still care about :)
          [color=blue]
          > 2.
          > <!-- // --> is still suggested: to hide inline scripts from webbots.[/color]

          Any webbot that doesn't recognize the script tag, but does recognize
          comments, is ... well, badly broken.
          [color=blue]
          > Still it is better to be safe than sorry.[/color]

          .... but that is a point.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Randy Webb

            #6
            Re: documnet.write

            VK wrote:
            [color=blue][color=green]
            >>this does not work
            >><script language="JavaS cript1.2"><!--
            >>
            >>if (document.all)
            >>document.writ e(document.body .clientWidth)
            >>
            >>//-->
            >></script>[/color]
            >
            >
            > This works OK on IE 6
            >
            > Firefox doesn't support document.all collection, so your "if" branch is
            > never executed.[/color]

            Actually, it does. It just won't let you test for it using
            if(document.all ). But, alert(document. all) in Firefox PR gives this:


            object HTML document.all class

            --
            Randy
            comp.lang.javas cript FAQ - http://jibbering.com/faq
            Answer:It destroys the order of the conversation
            Question: Why?
            Answer: Top-Posting.
            Question: Whats the most annoying thing on Usenet?

            Comment

            • Michael Winter

              #7
              Re: documnet.write

              On Mon, 25 Oct 2004 16:01:03 +0200, VK <schools_ring@y ahoo.com> wrote:
              [color=blue][color=green]
              >> The language attribute has been deprecated in favour of the (required)
              >> type attribute for over five years.[/color][/color]

              [snip]
              [color=blue]
              > 1.
              > A language indication in any form was needed only for a short period of
              > time between IE 3.0 - IE 3.02[/color]

              They are dead. An interesting aside, though.

              Even if those versions were a concern, it doesn't negate the fact that
              trying to invoke v1.2 is a bad idea.

              [snip]
              [color=blue]
              > As of 2004 A.D. <script></script> is enough, any extra would be a
              > useless "white noise".[/color]

              As Lasse said, that would result in invalid HTML. Unless you have a
              *really* good reason to do otherwise, all documents should be valid.
              [color=blue]
              > 2.
              > <!-- // --> is still suggested: to hide inline scripts from webbots.[/color]

              As I said in my earlier post: "If you really need to prevent a user agent
              from reading the script, move it into an external file."

              If a bot isn't smart enough to ignore the script, I highly doubt it would
              read the src attribute, download the resource, and analyse it.

              [snip]
              [color=blue]
              > 3.[color=green]
              >> A cross-browser solution has been presented by Richard Cornford in
              >> another thread[/color]
              >
              > This is a reputable name, and I'm sure in the quality of his code. But I
              > think that the OP wanted to have HER code to work, not Mr. Cornford's
              > one.[/color]

              There's nothing wrong with the OP's code, other than the erroneous test.
              It's perfectly valid, syntactially, so it will work. Whether it works as
              desired is another matter, but the OP didn't provide enough information to
              determine that. Unless an error occurs, the write method will write
              something.

              [snip]

              Mike

              --
              Michael Winter
              Replace ".invalid" with ".uk" to reply by e-mail.

              Comment

              • VK

                #8
                Re: documnet.write

                [color=blue]
                > Any webbot that doesn't recognize the script tag, but does recognize
                > comments, is ... well, badly broken.
                >[color=green]
                > > Still it is better to be safe than sorry.[/color]
                >
                > ... but that is a point.[/color]

                Exactly! Just to start with, check this:

                and look what kind of "oops" happened with Indiana University of
                Pennsylvania

                OK, this is why eventually AltaVista lost all its former glory and why the
                most people is googling instead of altavisting.
                Still AltaVista is not an amateur search site, and still used for
                cross-search.


                Comment

                • Randy Webb

                  #9
                  Re: documnet.write

                  VK wrote:
                  [color=blue][color=green]
                  >>Any webbot that doesn't recognize the script tag, but does recognize
                  >>comments, is ... well, badly broken.
                  >>
                  >>[color=darkred]
                  >>>Still it is better to be safe than sorry.[/color]
                  >>
                  >>... but that is a point.[/color]
                  >
                  >
                  > Exactly! Just to start with, check this:
                  > http://www.altavista.com/web/results...1&kls=0&stq=80
                  > and look what kind of "oops" happened with Indiana University of
                  > Pennsylvania[/color]

                  http://validator.w3.org/check?uri=ht...lib.iup.edu%2F


                  --
                  Randy
                  comp.lang.javas cript FAQ - http://jibbering.com/faq

                  Comment

                  Working...