Javascript onLoad error "Object doesn't support this action"

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

    Javascript onLoad error "Object doesn't support this action"

    I have the following script in an html page:

    function goToPosition()
    {
    varGoTo = document.write( document.cookie ("Position") );
    document.scroll To(0, varGoTo);
    }
    </head>
    <body onload="goToPos ition()">

    When I put the onload="goToPos ition()" in, I get the error message
    "object doesn't support this action". I've also tried putting in after
    the </body> tag as another script...no go.

    I'm setting the cookie with these lines in another function:
    varScroll = document.body.s crollTop; document.cookie ("Position") =
    varScroll;

    Any clues/suggestions greatly appreciated. I recently posted a similar
    question, but rearranged how I was doing it, still no luck, so I'm
    trying again.

    Thanks.
    Kathy
  • Klaus Johannes Rusch

    #2
    Re: Javascript onLoad error &quot;Object doesn't support this action&quot;

    KathyB wrote:
    [color=blue]
    > I have the following script in an html page:
    >
    > function goToPosition()
    > {
    > varGoTo = document.write( document.cookie ("Position") );
    > document.scroll To(0, varGoTo);
    > }
    > </head>
    > <body onload="goToPos ition()">
    >
    > When I put the onload="goToPos ition()" in, I get the error message
    > "object doesn't support this action". I've also tried putting in after
    > the </body> tag as another script...no go.
    >
    > Any clues/suggestions greatly appreciated. I recently posted a similar
    > question, but rearranged how I was doing it, still no luck, so I'm
    > trying again.[/color]

    A document.write after the document has fully loaded will _replace_ the current document with the new
    content, you can either place an empty div in the body and update the innerHTML or innerText propertly of
    that div, or use window.alert to show the information, but you cannot use document.write.

    --
    Klaus Johannes Rusch
    KlausRusch@atme dia.net



    Comment

    • Richard Cornford

      #3
      Re: Javascript onLoad error &quot;Object doesn't support this action&quot;

      "KathyB" <KathyBurke40@a ttbi.com> wrote in message
      news:75e8d381.0 309220722.6ea51 9d7@posting.goo gle.com...[color=blue]
      > I have the following script in an html page:
      >
      > function goToPosition()
      > {
      > varGoTo = document.write( document.cookie ("Position") );
      > document.scroll To(0, varGoTo);[/color]

      scrollTo is a global function (property of the window object) so:-

      window.scrollTo (0, varGoTo);
      - or -
      scrollTo(0, varGoTo);

      -would work better. But - document.write( ... ) - in/after the onload
      event (when the document has been closed) will clear the current
      document and replace it (along with JavaScript functions and variables.
      [color=blue]
      > }
      > </head>
      > <body onload="goToPos ition()">
      >
      > When I put the onload="goToPos ition()" in, I get the
      >error message "object doesn't support this action". I've
      >also tried putting in after the </body> tag as another
      >script...no go.[/color]

      After the body tag is an invalid location for a script tag, just before
      the body tag would be OK (and a much better place to be doing -
      document.write( ... ) - as the document will not yet have been closed.
      [color=blue]
      >I'm setting the cookie with these lines in another
      >function:
      >varScroll = document.body.s crollTop;[/color]

      The scroll offset is not always available as body.scrollTop. On many
      browsers that value is available as window.pageYOff set and on IE 5.5+
      browsers the scrollTop value should be read from
      document.docume ntElement instead of document.body when the page is in
      "standards" mode (document.compa tMode == 'CSS1Compat'):-

      var varScroll = 0;
      if(typeof pageYOffset == 'number'){
      varScroll = pageYOffset;
      }else if((document.co mpatMode)&&
      (document.compa tMode == 'CSS1Compat')&&
      (document.docum entElement)){
      varScroll = document.docume ntElement.scrol lTop;
      }else if(document.bod y){
      varScroll = document.body.s crollTop;
      }
      [color=blue]
      >document.cooki e("Position") = varScroll;[/color]
      <snip>

      document.cookie - is a string property of the document object and not a
      function so this syntax is incorrect.

      Richard.


      Comment

      • Kathy Burke

        #4
        Re: Javascript onLoad error &quot;Object doesn't support this action&quot;

        Thanks for the responses. I put the original together from other
        posts/examples, but now realize that I should not have used
        document.write. ..I just need to get the cookie value to set as the
        varScroll value, not actually write it?

        I still can't seem to get the cookie value (never used it before!).

        Re: document.cookie - is a string property of the document object and
        not a function so this syntax is incorrect...I'v e actually seen this
        used in example(s) so now I'm confused yet again.

        Thanks for the help!

        Kathy

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Richard Cornford

          #5
          Re: Javascript onLoad error &quot;Object doesn't support this action&quot;

          "Kathy Burke" <kathyburke40@a ttbi.com> wrote in message
          news:3f6f474b$0 $62080$75868355 @news.frii.net. ..
          <snip>[color=blue]
          >Re: document.cookie - is a string property of the document
          >object and not a function so this syntax is incorrect...I'v e
          >actually seen this used in example(s) so now I'm confused yet
          >again.[/color]

          Server-side ASP JScript, I think, has a cookie function on either the
          request or response objects (or both) that you may have seen used in
          this way. For client side cookie work you will have to find your own set
          of cookie functions. You might have a look at:-

          <URL: http://jibbering.com/faq/#FAQ4_4 > and follow the link in that
          section as it leads to a page with example cookie functions and some
          explanation of them and their use.

          Richard.


          Comment

          Working...