I have an existing lightbox with an image gallery (it has been created using the Wix upload functionality). I now want to get the image gallery and store it in a database. I am trying to get the image gallery with the following code in the lightbox page:
$w.onReady(function () {
let images = $w("#gallery1").items;
console.log(images.length); /// returns 0
});
For some reason, this does not work. I am using the same code on a normal page and there it works, so I guess there is something I need to do differently in a lightbox?
I forgot about this post, see if it helps you to get it sorted.
https://www.wix.com/corvid/forum/community-discussion/getting-all-image-url-s-in-the-media-manager
Have a read of this page about lightbox in gallery urls etc.
https://support.wix.com/en/article/lightbox-appearing-in-site-url
As for lightbox urls, have a look here.
Wix Code Courses - Getting a Lightbox URL
Does the lightbox have an url? Or can I somehow get the whole lightbox stored in the database? I guess that every lightbox must have some sort of code that makes it appear. I guess it is in the button that opens the lightbox?!
my problem is actually that I have like a hundred lighboxes which were created by somebody using Wix functionality (so no programming). Unfortunately, they used Wix Pro Gallery. What I want to do is to get all the galleries from the lightboxes into a database so that I can create a dynamic page instead of the hundred lightboxes.
So, if there is a way to get the gallery out of the Wix Pro Gallery into a database then I'd be keen to know.
Second question is whether there is maybe a way to change a Wix Pro Gallery to a normal Wix gallery using Wix functionality (this would solve the problem, since I could then just use the let images = $w("#gallery1").items; )
Is there a way to change the Wix Pro Gallery to a normal Slider Gallery. That would solve the problem!
Actually, just found the reason why I can't get the images through code. It's because it is a Wix Pro Gallery.
Here is the text from the 'item' method:
Note
You can only get the items of a Pro Gallery using the items property if you set its items using the items property or connect the gallery to a dataset first. If you set the gallery's items in the Editor, you are not be able to retrieve them with the items property. This limitation does not apply to standard galleries.
This really sucks. Is there a way this could be rectified or do you have another trick up your sleeve.
Chris
the problem is that I have not opened the lightbox programmatically. It was created using Wix functionality. So, when I run the getContext() function I get "undefined" in the console.
Somehow the lightbox is different to a normal page.
It is weird though that I can access text fields without a problem, only the image gallery is not working
You might need to simply pass the data from the lightbox back to the page.
How do I pass data between a page and a lightbox?
When you open a lightbox using the openLightbox() function, you can pass an object containing data to be used in the lightbox. In the lightbox's code, you call the getContext() function to retrieve the data sent by the openLightbox() function.
When you close the lightbox using the close() function, you can pass an object containing data to be used by the page that opened the lightbox. This data is retrieved from the resolution of the Promise returned by the openLightbox() function.
https://www.wix.com/corvid/reference/wix-window.lightbox.html