View Full Version : set innerHTML scrolls window to top?

01-27-2006, 04:24 PM

I'm working on a Java Applciation and would like to include AJAX so that large portions of the screen is dynamically updated without the page refreshing or the user loosing their place.

The AJAX side of things I have working very well (I'm using the excellent JSRS library). However, when I update the screen it scrolls back to the top of the page.

We're using IE 6. I'm updating the screen by locating a "div", then setting it's "innerHTML" property.

Any ideas please? With this scrolling problem, it is rendering the AJAX mechanism useless and (from a usability point of view) we may as well simply submit and refresh the screen as in a normal web application. :mad:


01-27-2006, 04:57 PM
... huh?
If it's a Java application, you needn't fiddle around with AJAX: Java has a very nice and perfectly usable java.net.Socket (http://java.sun.com/j2se/1.4.2/docs/api/java/net/Socket.html) class available.

01-30-2006, 10:30 AM
It's a J2EE Web Application, sorry for the confusion. :)

01-30-2006, 10:34 AM
I've fixed it myself anyway. In case anyone else is interested, the issue was that I was using an "a" tag to trigger JSRS:

<a href="#" onclick="myJSRSFunction(...);">Call JSRS</a>

A "feature" of IE is that this will scroll the window to the top after clicking!

The following gets around it:

<img src="..." onclick="myJSRSFunction(...);"/>

01-30-2006, 04:00 PM
That's a feature of any browser; because you are linking to a non-existant anchor in the page, it will simply scroll to the top. Try returning false from the onclick event, or using "javascript:void(0);" as the href instead of #.