Page redirect

I have been trying to put some javascript in a page to redirect the user if the referring page is not as desired. The code looks like this and it doesn’t work. Would someone give me some assistance please?
import wixWindow from ‘wix-window’;
$w.onReady( function() {
if (wixWindow.referrer !== “https://www.gbpc.ca/submit-to-competitions”) {
wixWindow.parent.location.href = “https://www.gbpc.ca/submit-to-competitions”;
}
}) ;

Hi,
In order to redirect to a page, you should use the Wix Location API :

import wixLocation from 'wix-location'; 
import wixWindow from 'wix-window';

$w.onReady( function() {
	if (wixWindow.referrer !== "https://www.gbpc.ca/submit-to-competitions") {
		wixLocation.to("https://www.gbpc.ca/submit-to-competitions");
	}
}) ;

Click here to learn more about the Wix Window API.

Best,
Tal.

1 Like

Hey Tal, so many thanks. I spent way too long trying to figure this out. Works great, much appreciated.

Is there a way to add a two or three second delay to this process?

Hi…
Is there anyway to redirect the user to our homepage?
Because I want to create a logout button,
And I input this code for my logout button,

export function outbutton_click() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
wixUsers.logout()
wixLocation.to(“/”);
}
}

but it did not succeed.

Hi,

I’m trying to create retargeting web audiences for Facebook ads and I would like to target people who were about to make a booking on my Wix site, but did not submit it. I could technically create this retargeting audience by including people who have seen the booking page but excluding people who have seen a confirmation page.

Since the confirmation page is the same as the booking page (I’m using Wix Bookings app), I am not able to do that. With Wix Bookings, the URL does not change once a booking is succesful.

Therefore, I was wondering if it was possible to create a redirect as soon as a booking is completed (e.g. from www.valentingallone.com/bookonline to www.valentingallone.com/applicationreceived ). What would be even better would be to have the same confirmation message on a new URL once booking is completed.

Therefore, I would be able to do my facebook audience retargeting for people who were about to book a consultation but did not complete it (since they did not get redirected to /applicationreceived)

If you need additional info, please let me know.

Thank you!!!

Valentin