wixLocation.path (Specific Page)

Hi

I have this code so far, but I doesn’t seem to be working.

I’m wanting a lightbox to load every time it lands on a certain page of my site (my forum home page, not the others / sub pages of the forum).

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

$w.onReady(function () {
	if (wixLocation.path == 'forum') {
		wixWindow.openLightbox('Main Menu');
	}
}); 

Is there a way of launching a lightbox on a specific page only not on all sub categories of the forum?

e.g only on 2 pages:

  1. www.example.com/forum/

  2. www.example.com

I was thinking of using wix-storage (local) to get round the issue but this doesn’t really fix the route of the problem.

Many thanks for any help

Thomas

Hi Thomas,
What do you receive in console.log(wixLocation.path) before the if condition ?
Roi

Hi Roi,

I’m fairly new at this coding malarky, unfortunately. Where would I find this?

The site is called:

It might give you an idea of what i’m trying to achieve with the lightbox

Best

Thomas

Hi,
Your logic is correct.
If (wixLocation.path == ‘forum’) could never be truthy becouse wixLocation.path is Array type and ‘forum’ is string type (unless the length is empty ‘’ == []). It can be truthy if you replace wixLocation.path with wixLocation.path[the position of the correct string in the array].
If forum is the home page of your site wixLocation.path would be equals to [“”]

Roi

Hi Roi

I’ve tried three other options and nothing seems to be working;

any more ideas? I’ve tried these variations

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

$w.onReady(function () {
	if (wixLocation.path == '') {
		wixWindow.openLightbox('Main Menu');
	}
}); 
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

$w.onReady(function () {
	if (wixLocation.path == "") {
		wixWindow.openLightbox('Main Menu');
	}
}); 

Try this:

$w.onReady(function () { 
    if (wixLocation.path[0] == "") { 		
        wixWindow.openLightbox('Main Menu'); 
        } 
}); 

Let me know if if works
Roi

Hi Roi

It loads on the opening screen (when I first load the site) but doesn’t load again while navigating around and then back home.

Also, it still loads when entering the site via a Facebook link to a sub category post.

Best

Thomas

This one works for me:
if (wixLocation.path.length === 0)
Roi

Hi Roi

I’ve tried using this version and now the lightbox isn’t showing at all. I’m not sure where I’m going wrong if it’s working for you?

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

$w.onReady(function () { 
    if (wixLocation.path.length === 0) { 		
        wixWindow.openLightbox('Main Menu'); 
        } 
});

Thomas

Alternatively I’ve tried running it via an Input Box and using said box as a validator to open/trigger the lightbox

Would something like this (or a variation of) work?:


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

let url = wixLocation.url;

$w.onReady(function () {
$w("#input1").value = url; 
	if (input1 === "https://www.example.com") {
		wixWindow.openLightbox('Main Menu');
	}
});

Hi,
That wont work.
You didn’t created the variable “input1”

import wixLocation from 'wix-location'; 
import wixWindow from 'wix-window'; 
  
$w.onReady(function () { 
    let url = wixLocation.url;
    if (url === "https://www.packerpal.com") { 		
        wixWindow.openLightbox('Main Menu'); 
        } 
});

This one works for me
Roi

Hi Roi

I’ve managed to get it working. But when I’m on the site, if I navigate to a category and then back to the home page, it doesn’t trigger the lightbox again. I physically have to reload the site in order to get the lightbox to popup again.

Is there any way to make it pop up everytime they navigate (within the site) back to the home page?

Also, it’s still popping up when I enter the site to a sub page / different page to the home screen?

Best

Thomas

Hi,
Have you tried my example ?
Roi

Hi Roi

This is using the code provided in your last example. It keeps opening on all screens regardless of landing page.

Also, it doesn’t re-load once while navigating the site?

Best

Thomas

Hi,
Can you please share a link to you site ?
Roi

The site’s called:

Sorry, it’s loading when I click back. But also loading on sub linked pages too and auto redirecting to home.

Many thanks

Thomas

The lightbox opens only on entry screen.
Can you video capture the unwanted scenario
You can use this tool: www.screencast.com
Roi

Hi Roi

Here is an example of when I use a link from facebook to one of the posts. Would be great if we could PM the ‘back of house / working examples’ so people can’t see my pre-site workings! (don’t mind the code bit, helps everyone along) (although I’ve read a fair few people mention that, so i’ll leave it alone!)

Here is an example of when I use a link from facebook to one of the posts. Would be great if we could PM the ‘back of house / working examples’ so people can’t see my pre-site workings! (don’t mind the code bit, helps everyone along) (although I’ve read a fair few people mention that, so i’ll leave it

Many thanks!

Thomas

Hi Roi

I’ve submitted a video as requested of the issue. I don’t suppose you have managed to further take a look at this have you?

Many thanks

Thomas

Hi Thomas,
I Did, this is an issue that we are working on. it may take some time to fixed.
Roi