I have a page with products, and when I add a product to the wishlist or shopping cart, my screen jumps to the top of the page.

Is there a way I can stay at the same scrollposition after I add a product to my cart or wishlist from my category page.

  • Have you using infinite scroll of your product page
    – Gem
    Jun 30, 2016 at 9:49
  • I don't need an infinite scroll on my page (you mean this extension, right? Strategery - InfiniteScroll) I just need to stay at the same scroll position after I add an item to my wishlist or shopping cart.
    – Mand
    Jun 30, 2016 at 9:51
  • There may be a "#" symbol as href on those links. This can trigger this behavior. Check for this.
    – Prateek
    Jun 30, 2016 at 11:29
  • There isn't a "#" in the link. And even if it would been, I still need to figure out how to trigger a method on that anchor link.
    – Mand
    Jun 30, 2016 at 12:25

1 Answer 1


I figured it out using jquery.

code :

//  Get the scrollposition after adding a product to the wishlist or shopping cart

//Loading the document
    jQuery(document).ready(function() {
        // If scroll location cookie is set, and the location is the same
        //scroll to the position saved in the scroll cookie.
            if ( jQuery.cookie("scroll") !== null && jQuery.cookie("location") !== null 
                    && jQuery.cookie("location") == jQuery(location).attr('href')) {
                jQuery(document).scrollTop( jQuery.cookie("scroll") );

                jQuery("#grid").click(function () {
                    // Set cookie with current location
                    jQuery.cookie("location", jQuery(location).attr('href'));
                    // Set cookie with current scrollposition from the top
                    jQuery.cookie("scroll", jQuery(document).scrollTop() );
  • Great solution! Works like a charm for Magento 2.3.3 Jan 13, 2020 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.