Skip to content


Subversion checkout URL

You can clone with
Download ZIP


about lastscroll in the nightly version #1774

badtoto opened this Issue · 13 comments

7 participants


lastscroll doesn't work


Agreed. The scrollback function seems to be broken in beta 1 / latest:

Scroll down, tap Next Page, then tap the browser Back button to return to the first page.

Expected behaviour: JQM scrolls the page down to the Next Page link.
Actual behaviour: The user is returned to the top of the first page.

This is on iPhone 4 / iOS 4.3.3.

The scrollback works on 1.0a4.1.


From what it appears... if you create a button instead of a standard link, the last scroll functionality works fine (in my testing environment of Firefox), but if you create a standard link, last scroll does not work properly.

I've been trying to dig through the code to debug this further, but at first glance it's a bit overwhelming.


Well, it appears that a button works because it has the .ui-btn class attached to it. A silly test of adding the ui-btn class to any standard link makes that link work. As for an immediate fix, I simply changed this line:

            $activeClickedLink = $link.closest( ".ui-btn" );

... to ...

            $activeClickedLink = $link.closest( "a" );

I'm not sure if that's what was intended, but for me, it appears to be doing the job.


Hopefully one final update to this... a better selector would probably be:

            $activeClickedLink = $link.closest( ".ui-btn, .ui-link" );

That will probably be closer to what was intended.


@jasonaward : That looks like a good fix to me!


Thanks! I'll take a look and try and get this (or another) fix in for b2.

@scottjehl scottjehl was assigned

So, lastScroll no longer works primarily because we stored the lastScroll data on the page element, which is now removed after pagehide. Also, storing a reference to $activeClickedLink as shown above will simply leak memory on most pages (aside from returning to home), since a page and its child elements are removed from the DOM on pagehide.

I've started a branch ( with one commit that does the following.

  • This change sets the "lastScroll" property to each urlHistory item object, allowing us to remember previous scroll distances when returning to a page that has since been removed from the DOM. Before this change, this number was stored in data on the page element, so it is lost when the page is removed after pagehide.
  • Also, this change removes a reference in memory that we were keeping to the $activeClickedLink on each page. We stored this in attempt to refocus a link after returning to a page. Unfortunately, it doesn't seem that this data can be retained after pages are removed from the DOM, outside of somehow remembering a unique selector string to reach that element again (which could be achieved by adding some overhead, ala )

The diff is here:

Feedback is much appreciated. thanks!

@jblas jblas was assigned
@scottjehl scottjehl was assigned

Scott - should we merge in this branch? Been a while and no word from anyone on this ticket.


This appears to be working correctly (including the latest changes to the branch from 2 days ago) from our testing.

Let me know if you have any questions before this can be pushed into master. Thanks!


Now fixed:

@toddparker toddparker closed this

I feel like this is still an issue in IE 7/8. I'm wondering if anyone else has noticed this?


@nareneko - Can you create a jsbin or jsfiddle we can test?


I created a page with a listview of 30 items. If you scroll down to the bottom and click on one of the later items, it will display a dialog. When I click out of the dialog, it should take me back to the last scroll position of the first page of listview items. In IE 7 & 8, it doesn't seem to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.