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

Discussion in 'Javascript' started by KathyB, Sep 22, 2003.

  1. KathyB

    KathyB Guest

    I have the following script in an html page:

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

    When I put the onload="goToPosition()" 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.scrollTop; 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
    KathyB, Sep 22, 2003
    #1
    1. Advertising

  2. KathyB wrote:

    > I have the following script in an html page:
    >
    > function goToPosition()
    > {
    > varGoTo = document.write(document.cookie("Position"));
    > document.scrollTo(0, varGoTo);
    > }
    > </head>
    > <body onload="goToPosition()">
    >
    > When I put the onload="goToPosition()" 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.


    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

    http://www.atmedia.net/KlausRusch/
    Klaus Johannes Rusch, Sep 22, 2003
    #2
    1. Advertising

  3. "KathyB" <> wrote in message
    news:...
    > I have the following script in an html page:
    >
    > function goToPosition()
    > {
    > varGoTo = document.write(document.cookie("Position"));
    > document.scrollTo(0, varGoTo);


    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.

    > }
    > </head>
    > <body onload="goToPosition()">
    >
    > When I put the onload="goToPosition()" 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.


    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.

    >I'm setting the cookie with these lines in another
    >function:
    >varScroll = document.body.scrollTop;


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

    var varScroll = 0;
    if(typeof pageYOffset == 'number'){
    varScroll = pageYOffset;
    }else if((document.compatMode)&&
    (document.compatMode == 'CSS1Compat')&&
    (document.documentElement)){
    varScroll = document.documentElement.scrollTop;
    }else if(document.body){
    varScroll = document.body.scrollTop;
    }

    >document.cookie("Position") = varScroll;

    <snip>

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

    Richard.
    Richard Cornford, Sep 22, 2003
    #3
  4. KathyB

    Kathy Burke Guest

    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've 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!
    Kathy Burke, Sep 22, 2003
    #4
  5. "Kathy Burke" <> wrote in message
    news:3f6f474b$0$62080$...
    <snip>
    >Re: document.cookie - is a string property of the document
    >object and not a function so this syntax is incorrect...I've
    >actually seen this used in example(s) so now I'm confused yet
    >again.


    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.
    Richard Cornford, Sep 23, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fabio R.
    Replies:
    0
    Views:
    792
    Fabio R.
    Mar 25, 2005
  2. David Otton

    window.onload and body.onload differences

    David Otton, Nov 4, 2004, in forum: Javascript
    Replies:
    2
    Views:
    545
    Martin Honnen
    Nov 4, 2004
  3. Replies:
    5
    Views:
    257
    Thomas 'PointedEars' Lahn
    May 15, 2005
  4. Darren
    Replies:
    3
    Views:
    110
    Darren
    Sep 1, 2005
  5. marco

    onload -->* no onload

    marco, Jun 22, 2006, in forum: Javascript
    Replies:
    7
    Views:
    202
    marco
    Jun 24, 2006
Loading...

Share This Page