Jquery Mobile go back button scrolls to top

0 votes

In my Jquery Mobile website I am using href for back button like;

 <a id='{0}' class='{1}' href='/' data-role=""button"" data-icon=""arrow-l"" data-transition=""slide"" data-direction=""reverse"">

but if I have scroll on first page, back button jumps back to top again. First page does not stay on same position.

Is there any solution for this?

Aug 4, 2022 in Web Development by gaurav
• 23,260 points
732 views

1 answer to this question.

0 votes

I had this issue i fixed it using iSroll

While going from PageA to PageB save the scroll position of PageA in a variable.

to do this modify the iscroll.js and add getScrollY method under scrollTo like this

        scrollTo : function(x, y, time, relative) {
            var that = this, step = x, i, l;

            that.stop();

            if (!step.length)
                step = [{
                    x : x,
                    y : y,
                    time : time,
                    relative : relative
                }];

            for ( i = 0, l = step.length; i < l; i++) {
                if (step[i].relative) {
                    step[i].x = that.x - step[i].x;
                    step[i].y = that.y - step[i].y;
                }
                that.steps.push({
                    x : step[i].x,
                    y : step[i].y,
                    time : step[i].time || 0
                });
            }

            that._startAni();
        },
        getScrollY : function() {

            var that = this;

            return that.y;

        },

Now save the current position before page change like this

curScrollPos = myScroll.getScrollY();

And set the scroll position while going back to that PageA, i am doing this on pagehide event of PageB

myScroll.scrollTo(0, curScrollPos, 1);
myScroll.refresh();

This way i solved my issue, hope this helps.

answered Aug 5, 2022 by rajatha
• 7,680 points

Related Questions In Web Development

0 votes
0 answers

How to check radio button is checked using JQuery?

I have two radio buttons in one ...READ MORE

Jun 29, 2022 in Web Development by gaurav
• 23,260 points
490 views
0 votes
0 answers

How to scroll to top of page with JavaScript/jQuery?

Is there a way to control browser ...READ MORE

Jul 1, 2022 in Web Development by gaurav
• 23,260 points
2,254 views
0 votes
0 answers

how to trigger on jquery.smart wizard Finish button?

Iam very new in jquery. here is ...READ MORE

Jul 19, 2022 in Web Development by gaurav
• 23,260 points
2,579 views
0 votes
0 answers

How to get mobile number from facebook login using jquery?

I am trying to work facebook login ...READ MORE

Jul 19, 2022 in Web Development by gaurav
• 23,260 points
811 views
0 votes
1 answer

Horizontal scrolling and vertical scrolling in JqueryMobile

I'll go through code's main parts for ...READ MORE

answered Jun 21, 2022 in JQuery by rajatha
• 7,680 points
1,824 views
0 votes
0 answers

Page Reload/Refresh executes $(document).ready() on every page in jQuery Mobile

My jQuery mobile applications consists of multiple ...READ MORE

Jul 22, 2022 in Web Development by gaurav
• 23,260 points
935 views
0 votes
1 answer

What is jQuery?

Hey, jQuery is a fast and concise JavaScript ...READ MORE

answered Feb 14, 2020 in JQuery by kartik
• 37,520 points
1,317 views
0 votes
1 answer

Uncaught TypeError: Cannot read property 'msie' of undefined - jQuery tools

Hello, Use the following script tag in your ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
15,711 views
0 votes
1 answer

How to change the jquery mobile flip switch state from code

I've examined the page you posted and ...READ MORE

answered Aug 1, 2022 in Web Development by rajatha
• 7,680 points
714 views
0 votes
1 answer

How to place images using jQuery masonry plugin to start

You were just missing a css class that adjusts ...READ MORE

answered Jun 22, 2022 in Web Development by rajatha
• 7,680 points
556 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP