Event Handler on Back Button

I am still struggling with this issue. I have created a dynamic page with a simple “X” in the top right corner. The user should be able to click on this and be taken BACK to the previous page from their session (like the “back” arrow on their browser bar). Please can you give SPECIFIC instructions or even better a tutorial on how to do this. I am assuming that I can create an event handler in the onClick from the Properties menu - but I know very little about coding so don’t know what I should be doing from here. I have tried to subcontract this issue out to a Freelancer but everyone who looks at it is saying Wix javascript is different from regular javascript!!! Please help!!!

Few question to better understand your scenario:

  1. What happens if user goes directly to this dynamic page from another site? Should the x button take him out of your site?
  2. Do you have a lot of different pages on your site that point to these dynamic pages or is it only one page? (If it’s the second maybe you can have the X link always to a specific page?)

Hi Yotam - Thanks
1)The user can ONLY access the dynamic page from an Index page on my site - they can’t access them from another site.
2) They can access the dynamic page from various points throughtout the site (presently 10 different index pages) so the X link back to just one specific page won’t be appropriate.

Hi monoliver,

Just a thought:
How do you prevent the user from getting there directly by typing the URL?

Regarding what you want to do.
Use wixStorage (session storage) to keep track of a users all steps on your site, then, in your X button onClick(), check the latest page there and navigate there.

Assuming you have a button that takes you to the dynamic page, called ‘#button1’.
some simple example:

import {session} 'wix-storage';
import wixLocation from 'wix-location';

    // some page code

export function button1_onclick() {
    const currentPageName = wixLocation.path[0];
    session.setItem('previousPage', currentPageName);
    //go to whatever page you like

Then, on the dynamic page, X button function will look a bit like:

export function buttonX_onclick() { 
    //get the saved value
    const previousPageName = session.getItem('previousPage');
    //go to whatever page you like     

Adjust that code to your site.


Hi Liran - thanks so much - will give this a go.

I can’t prevent a user from typing in the URL directly - but tbh this is highly unlikely. Presumably in that scenaria the “back” button won’t work - but I can live with that;)

Cool… hope this helps :slight_smile:

can’t make this code work on a single blog page so users can go back to where they were before. Any suggestions?

Hi Javier,

Unfortunately there’s an issue wix wixLoaction.path on apps like blog, you only get ‘/blog’ and not the rest of the URL. We are aware and fixing it.



Isn’t there a step by step explanation on how to create a back button to go to the last visited page?
I can’t seem to get this to work

Missing a “from” in import?