By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,679 Members | 2,602 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,679 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #2

P: n/a
"KathyB" <Ka**********@attbi.com> wrote in message
news:75**************************@posting.google.c om...
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.
Jul 20 '05 #3

P: n/a
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!
Jul 20 '05 #4

P: n/a
"Kathy Burke" <ka**********@attbi.com> wrote in message
news:3f***********************@news.frii.net...
<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.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Browse more JavaScript / Ajax / DHTML Questions on Bytes