Custom Code to prevent People from clicking back button

I want to make it so when people make it to my upsell pages in my funnel they are not able to go back to the checkout page and accidentally place a duplicate order.

I cant add links so here is an image with the link to an example of what I mean, just click through their no button and then try to go back

1 Like

I cant add the image actually if a mod can either fix that or dm me where I can try sending the image there that would be greatly appreciated!

1 Like

Hey @Sarah_Smith,

This is a common headache with funnel flows. Since we can’t actually “disable” the browser’s back button (browser security won’t allow it), we have to get a little creative with how the page handles that “Back” click.

Here are the two best ways to handle this directly inside Funnelish to keep your customers moving forward.


Option 1: The “History Lock” (Best for Upsells)

This is the “pro” way to do it. It basically tricks the browser into thinking there’s a new page in the history stack. When the customer clicks back, they just “land” on the same upsell page again.

How to set it up:

  1. Open your Upsell Page in the Funnelish editor.
  2. Go to Page Settings > Custom Codes.
  3. Paste this into the Footer Tracking section:
<script>
  // Push an extra entry so the 'back' button has nowhere to go
  history.pushState(null, null, location.href);

  window.onpopstate = function() {
    // If they try to go back, force them to stay right here
    history.go(1);
  };
</script>

Option 2: The “Safety Warning” (Best for Data Protection)

If you’d rather give them a “Hey, wait!” heads-up, this triggers a browser pop-up if they try to leave the page or hit back. It’s great for preventing those accidental double-taps.

How to set it up:

  1. In the same Footer Tracking area, use this code instead:
JavaScript<script>
  window.addEventListener('beforeunload', function (e) {
    // Modern browsers show a standard "Are you sure?" message
    e.preventDefault();
    e.returnValue = ''; 
  });
</script>

:light_bulb: Which one should you use?

For an upsell specifically, Option 1 is usually the winner. It keeps the momentum going and ensures they either click your “Yes” or “No” buttons to progress to the Thank You page.

One quick tip: Only put these on your Upsell or Downsell pages. You definitely want people to be able to navigate freely while they are still on the initial Checkout page!

Hope that helps clear up the loop! :rocket:

2 Likes

Thank you! That is exactly what I was looking for

1 Like