top of page
Anchor 1
Wix Tutorial - Back button to a previously visited page, using Wix Code
This example shows how to use a Back Button for a site visitor to return to the previously viewed page. This only works when the site is published and doesn't work in the Editor.
Elements:
Elements:
-
Page Back Button: #BackButton | Pinned & Show on all pages
Wix Code (on site tab):
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("#BackButton").link = previousPageURL;
$w("#BackButton").target = "_self";
});
Demo:
(see right side of page)
bottom of page