A Shopify store owner wants to modify the cart notification popup’s “Continue Shopping” button to redirect users to their previous browsing page instead of the product page.
Initial Solutions Proposed:
One user suggested using localStorage to track and store the previous page URL, then redirect using JavaScript in the theme.liquid file
Another participant mentioned trying window.history.back() but found it unreliable after page refreshes or external referrals
Technical Issue:
The original poster reported that after implementing the first solution, the cart stopped displaying added products on mobile devices
Final Working Solution:
Use document.referrer instead of localStorage for simpler, more reliable tracking
Add JavaScript code in theme.liquid before the </body> tag that listens for “Continue Shopping” clicks
The code redirects to document.referrer (previous page) or falls back to homepage if no referrer exists
Alternative redirect options include homepage (Shopify.routes.root) or all products collection
Resolution: The issue was successfully resolved using the document.referrer approach, which the original poster confirmed as working.
Summarized with AI on October 27.
AI used: claude-sonnet-4-5-20250929.
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 showen 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.
Please walk me through step by step on how solve it with pictures.
After editting and saving the theme.liquid file, the added product did not appear in the cart on the mobile version. Can you help me solving this issue? Thank you.
I’ve been trying to adjust the “Continue Shopping” link that appears in the cart notification popup. Right now, it just sends users back to the product page, but I’d like it to take them back to the actual page they were on before adding the item—like a collection, blog, or landing page.
I tried adding a bit of JavaScript using window.history.back() so it pulls the browser’s previous page. It does send them back in most cases, but it’s not always reliable, especially if they refreshed the page or came from an external site.
This will return you to a literally previous page.
You can replace document.referrer with Shopify.routes.root to redirect people to homepage or Shopify.routes.root + “collections/all” to send them to your “all products” collection…