[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 6217
  • Last Modified:

Scrolltop and onscroll javascript for firefox

We use a javascript function to postback (asp.net) to the same position on the page. This function does not seem to work with Firefox -- i think its because onscroll is not recognized.

<BODY ID="Body" runat="server" ONSCROLL="bodyscroll()" BOTTOMMARGIN="0" LEFTMARGIN="0"
            TOPMARGIN="0" RIGHTMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0">

<script language="JavaScript"><!--
         function bodyscroll() {
           var F=document.forms[0];
           F.ScrollTop.value=Body.scrollTop;
         }
         //--></script>

<INPUT ID="ScrollTop" runat="server" NAME="ScrollTop" TYPE="hidden">

Can someone recommend the best way to modify this script to work with firefox and safari also?

Thanks for any tips!
0
bda01
Asked:
bda01
  • 3
1 Solution
 
ZvonkoSystems architectCommented:
Here you go:

<script language="JavaScript"><!--
         function bodyscroll() {
           document.forms[0].ScrollTop.value=document.body.scrollTop;
         }
         //--></script>


Better would be to give a name to the form and access the the form by name:
<script language="JavaScript"><!--
         function bodyscroll() {
             document.myForm.ScrollTop.value=document.body.scrollTop;
         }
         //--></script>

0
 
bda01Author Commented:
I don't understand how this would help... I was under the impression that the OnScroll in the form tag was what was causing issues...

Thanks for the reply!
0
 
ZvonkoSystems architectCommented:
The problem was that your function did not reference the document.body correctly for Netscape.
Your syntax works only in IE.
0
 
ZvonkoSystems architectCommented:
Does it now work for you with my script version?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now