How to create a back button

Is there a solution to this issue?

I have two landing pages In each of them different products to purchase .
When the customer reaches the cart page Continue shopping button
Directs him to the main page of the site .( That’s not what I need)

that why I need to add a button that will return him to the page he came from.

anyone have a solution?

1 Like

I’m not sure if you can add wixLocation.to to that button, but if you can, you can get the referral and then direct it to it.

thanks
How do I get the referral ?
I tried some code I found here but it does not work
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;

export function backbutton1_click(event, $w) {
let url = wixWindow.referrer
wixLocation.to(url)
}

When visitors move from page to page within your site, the referrer property does not contain the address of the page the visitor came from. This is because Wix sites are built as single page applications . To get the previous page a visitor was visiting within your site, you can use wix-storage to store the visitor’s current page and retrieve the visitor’s previous page.

Here is a very simple example of a “back button” site:

I hope this helps.

Thank you very much! it’s work great.

Hi I am a complete noob and I am wanting to add a Back button like this on the Product Page so it takes the user back to previous store page they were on. How would i even go about making this button with the proper code for it?

@yisrael-wix I tried this and it is working fine in Edge but the button doesn’t do his job in Firefox. Any idea why that is?

How to create back button at service details ?

Veryyyyyy thanks a lot <3

Hey for some reason this code stopped working for me. Did something get deprecated? There is other code involved in the section but it shouldn’t be interfering. If I put this in masterPage.js it shows #backbutton in red. I don’t have backbutton in all pages only some of them. Thanks!

import { cart } from ‘wix-stores’ ;
import { formFactor } from ‘wix-window’ ;
import wixData from ‘wix-data’ ;

import wixWindow from ‘wix-window’ ;

import { session } from ‘wix-storage’ ;
import wixLocation from ‘wix-location’ ;

let previousPageURL ;
let productID ;
let productPrice ;
let originalprice = 0 ;
let neworgprice = 0 ;

//back button code
$w . onReady ( function () {

previousPageURL  =  session . getItem ( "page" ); 
console . log ( previousPageURL ); 
session . setItem ( "page" ,  wixLocation . url ); 
$w ( "#backbutton" ). link  =  previousPageURL ; 
$w ( "#backbutton" ). target  =  "_self" ;

Code below!


import wixWindow from 'wix-window';

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

let previousPageURL;

$w.onReady(function () {

    previousPageURL = session.getItem("page");
    console.log(previousPageURL);
    session.setItem("page", wixLocation.url);
    $w("#btnBack").link = previousPageURL;
    $w("#btnBack").target = "_self";
});

Credit to:
name: Yisrael (Wix)
posted: Dec 31, 2018
Awarded: Best Answer

p.s. added the code here for so it’s super easy for members to copy and paste. Thanks so much! This worked a TREAT on my platform too!

Many thanks

1 Like

Hello! For anyone struggling with this, make sure you put the code that Impact Designs posted into the masterPage.js file. Then insert a button into whichever page you want to have a back button. Set the button’s ID to “btnBack”. Enjoy!

Hi! I copies this code into the masterPage.js file and added the button ID. But when I try the button on site, it doesn’t link anywhere. What am I possibly doing wrong?

The solution is now available in App Market: Back Button: Go Previous Page | Wix App Market | Wix.com