Get the name of a lightbox

I’ve searched a lot in the forum and over internet, but I didn’t found any documentation about it.

About passing data from one page to the lightbox and vice versa there are a lot, but you always need to know the name of the lightbox.
Well, I need to be able to capture the name of the light box.

I don’t know if it’s applicable, i’m new working with code, but I tried something like that:

import wixWindow from ‘wix-window’;
"let unknownLightboxName= wixWindow.openLightbox.name"

No errors found neither syntax nor execution, but in any case it didn’t work.
Any help would be appreciated.

Thanks for your help.

You can use wix-site.currentPage .

Something like this:

import wixSite from 'wix-site';

...
 
let current = wixSite.currentPage;
/*
 * returns the following
 *  {
 *    "name": "Welcome (Full Screen)"
 *    "type": "lightbox"
 *  }
 */

Hello Yisrael, thank you so much for your quick response.
It has been very useful to me, but I still have to much work to do. I hope you can help me.
The page that I used for the test, has only three fields to collect the data, and a button to launch the Lightbox, so I be able to check if the result is correct.
I also include a Dataset to complete the test by recording the data obtained.
I have placed the code in the page tab of the code editor.
I also did tests with the code in the Site tab, alternating also the button between the two spaces, but the result has been the same or worse than the one I show you now.
I hope that the format is kept at least a little so that reading is more comfortable.
Below I have put the code that I used and the result on the test page.

import wixSite from “wix-site”;
import wixUsers from ‘wix-users’;
import wixWindow from ‘wix-window’;

// GET LIGHTBOX NAME ----------------------------------------------------------------------------------

export function iconButton1_click_1(event) {

wixWindow.openLightbox(“ADVERTENCIA ELIMINAR”); // OK - Lightbox open

let lbxcurrent = wixSite.currentPage; // FAIL - Get the page not the Lightbox

let lbxname=lbxcurrent.name; // OK, but for page not for Lightbox
let lbxtype=lbxcurrent.type; // OK, but for page not for Lightbox
let lbxinfo= lbxname + " / "+ lbxtype; // OK

$w(“#input4”).value = lbxinfo; // OK - Show the data in a page input field

$w(“#dataset1”).setFieldValue(“campo1”,lbxinfo); // FAIL - The data wasn’t saved in the dataset
// element field (it always worked fine in other
// processes over datasets with the same
// privileges in my site)
//$w(‘#dataset1’).save() // Nothing happens if I activate it

}

//---------------------------------------------------------------------------------------------------------------
// As an alternative to get the Lightbox name I used this part of code but didn’t worked either.
// Assuming the sintax is correct (probably not), no data is captured.
// Making diferent test with the sintax, in the best of cases, I get “undefined” as value, but in most
// cases nothing happened.

//let structure = wixSite.getSiteStructure(); // instead of " let lbxcurrent = wixSite.currentPage;"
//let lightboxes = structure.lightboxes; // and so on.

//let lbxinfo=lightboxes.name;
//$w(“#input4”).value = lbxinfo;
//$w(“#dataset1”).setFieldValue(“campo1”,lbxinfo);
//---------------------------------------------------------------------------------------------------------------

// GET PAGE, LOGGED USER AND USER EMAIL INFO -----------------------

$w.onReady( function () {

let current = wixSite.currentPage; // OK - Get the page
let pagename=current.name; // OK - Get the page name
let pagetype=current.type; // OK - Get the page type
let pageinfo= pagename + " / "+ pagetype; // OK - Concat name and type

$w(“#input6”).value = pageinfo; // OK - Show the data in a page input field
let user = wixUsers.currentUser; // OK - Get the logged user

user.getEmail().then((email) => {
let userEmail = email; // OK - Get the logged user email

$w(“#input7”).value= userEmail; // OK - Show the logged user email in a page input field

$w(“#dataset1”).setFieldValue(“campo3”,pageinfo); // FAIL - the data wasn’t saved in the dataset
// element field
$w(“#dataset1”).setFieldValue(“campo4”,userEmail); // FAIL - the data wasn’t saved in the dataset
// element field
//$w(‘#dataset1’).save() // Nothing happens if I activate it
})
})

@opadia2019

You say that this line fails:

let lbxcurrent = wixSite.currentPage;        // FAIL - Get the page not the Lightbox 

This will not return the lightbox since you have this in the page code. You will need to have this line of code in the Lightbox’s code.

Hi, thanks again for your quick response, not like mine.

I tried to do what you recommended but it didn’t work.

Simply placing the instruction in the window of the Lightbox doesn’t go, because then, on the page, it fails to recognize the variables that follow it.

I have tried to put the instructions to pass the variable with the name of the Lightbox, from this to the page, but I don’t get it. I’m having trouble solving it. Being self-taught is not easy sometimes.

If you can help me, I’d appreciate it because, honestly, I’m stuck.

Thank you.

@opadia2019 If it doesn’t recognize the varialbles on the Lightbox page code, that means that yoiu didn’t declare them. To get the name of the current page - whether it’s a regular page or a Lightbox - the code needs to be on the page itself.

If you continue to have problems, please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.