Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onscroll and scrollTop properties doesn’ t work in Netscape

Status
Not open for further replies.

cesark

Programmer
Dec 20, 2003
621
0
0
Hi,

How can I write these two functions so that it works in Netscape browsers?
Code:
  function SaveScrollLocation () { 
   document.index_form.hidden3.value = document.body.scrollTop; }
  document.body.onscroll=SaveScrollLocation ;

  function SetScrollLocation () {
   document.body.scrollTop ; }

Thanks
 
Which version of Netscape? I'm using Netscape 7.2, and the scrollTop property is reading OK for me.

Which bit of it doesn't work for you - getting or the setting?

Have you tried putting alert statements in to debug this?

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Aaah - it's the onscroll event that is not supported. Given this, probably the only way you'll achieve this in NN is with a timer - but that's a really bad solution, IMHO.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes, the scrollTop works in Netscape. The problem is the onscroll event which it doesn' t work, but it must be an alternative solution..

What about this?:
Code:
setInterval('doScroll()',100)=SaveScrollLocation ;
instead of:
Code:
document.body.onscroll=SaveScrollLocation ;
 
but it must be an alternative solution..

Yes - I mentioned that in my post - but I don't think it's anywhere near as neat.

Perhaps if you explain why you want to save the screen position, another solution may be forthcoming.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Perhaps if you explain why you want to save the screen position, another solution may be forthcoming.

Oh yes, as you probably know there are several ways to maintain scroll position after a page postback or after return to a previous page. So, I want to save the screen position in a hidden field (or pass it through querystring) in order to recuperate the same scroll position.
 
Imagine you are in page ‘A’, and you scroll that page until the bottom, then you save that scroll position in a hidden field and pass that value through querystring to next page ‘B’. Then, when you return to page ‘A’ from page ‘B’, you take (pass) again that value from querystring now to page ‘A’, and when page ‘A’ is load this script is executed:
Code:
function SetScrollLocation () {
  document.body.scrollTop = " & Request.QueryString("Scroll_pos") & "; }

And the scroll position of page ‘A’ will be the same as when we left that page.

All this mechanism works perfect in IE browser. But the ‘only’ problem with Netscape browsers is how to save the current scroll position of the page in a hidden field, as the script I posted does perfectly in Internet Explorer:
Code:
  function SaveScrollLocation () { 
   document.index_form.hidden3.value = document.body.scrollTop; }
  [b]document.body.onscroll[/b]=SaveScrollLocation ;

It’ s easy,.. the only thing I need is an alternative and/or equivalent to ‘document.body.onscroll’ method for Netscape browsers. Nothing else..

Thanks
 
Well - in this case, I'd argue that you don't need to use onscroll.

If you're only needing to save the screen position when you leave the page (such as form submission, link click, etc)... then why not only save the scroll position at those times?

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Perhaps you are right. I am trying to add the onclick event to a link so that to do so (trigger a script to save the scroll position when clicked), the problem is that link also has an onclick 'server' envent handler, and I don' t know how to add another onclick event to it. When I get it, which seems complicate :), I will test your reasonable suggestion.

Thank you
 
the problem is that link also has an onclick 'server' envent handler, and I don' t know how to add another onclick event to it.

You can have multiple commands in an onclick attribute:

Code:
onclick="someFunc1(); someFunc2(); ... someFuncN();"

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I finally found the alternative I mentioned to 'document.body.onscroll', is 'window.onscroll' ;-).
And works fine in Netscape 7.2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top