How do I redirect the "continue shopping" link to the previous page?

Topic summary

A Shopify store owner is experiencing an issue with the cart notification popup’s “continue shopping” link. The goal is to redirect customers back to the exact previous page they were browsing, rather than the product page or homepage.

Current Problem:

  • Implemented JavaScript code using history.back() to handle the redirect
  • Code works on desktop but fails on mobile view
  • A screenshot was provided showing the cart notification interface

Secondary Issue Identified:

  • A responder noticed that products have a 3-quantity minimum requirement displayed on the product page
  • However, customers can currently add fewer items to cart and checkout, bypassing this restriction

Status:

  • The original poster confirmed both issues and requested help without using third-party apps
  • A developer offered to assist with custom coding and requested collaborator access to the Shopify store
  • Discussion remains open, awaiting store access for implementation
Summarized with AI on October 27. AI used: claude-sonnet-4-5-20250929.

Hello all,

When a customer adds a product to the cart, a cart notification pop up window appears. On the cart notification pop up window, there is a “continue shopping” link shown and when it clicked, it just goes back to the product they have selected. Instead, I want the “continue shopping” to go back exactly to the previous page not to the home page or other pages.

I have used the below code but it didn’t work appropriately on mobile view. The code I have used:

But as I said it didn’t work appropriately on mobile view. Please walk me through step by step on how solve it with pictures.

My URL: https://u7yeji-na.myshopify.com

Well i guess the previous page option is solved as your code is mostly correct.

One thing I see is that on your pdp page it mentions that users need a to add min 3 quantities but I am still able to add to Cart and proceed to checkout lower than that.

Hi @Shadab_dev ,

Yes, you are right. Customers can add to cart and proceed to checkout with 1 quantity while they should add to cart no less than 3 quantities. So, can you please help me with this issue without using third party apps? Hope you can help me.

Regards,
Mamdouh

Yeah, this is probably achieveabke with custom coding. Will need Collab access for a convenient process.

Share the Collab access or you can invite me to your store.

Best