# How to trigger a Lightbox with Specific Content from Containers

**URL:** <https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926>\
**Category:** Ask the community\
**Tags:** question, wix-studio, cms\
**Created:** [December 21, 2024, 8:14am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926 "2024-12-21T08:14:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![samyak\_prajapati](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samyak_prajapati/32/102090_2.png) [@samyak\_prajapati](https://forum.wixstudio.com/u/samyak_prajapati)\
**Post date:** [December 21, 2024, 8:14am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/1 "2024-12-21T08:14:43Z")

</div>

**Question:**

# How to trigger a Lightbox with Specific Content from Containers

**Product:**  
Wix Studio Editor

**Current Setup:**  
I have a simple page with three containers. Each container contains a specific image and some text. I have also created a lightbox.

**Requirement:**  
I need each container to trigger the lightbox when clicked. The lightbox should display the same image contained in the clicked container (e.g., clicking on the first container with “Test Image 10” should open the lightbox displaying “Test Image 10”). This functionality should apply to all containers.

How can I achieve this?

**What have you already tried:**  
I have already explored creating a dynamic page, using CMS, and the Wix Pro Gallery. However, these options do not meet my requirements, as I need a custom layout for these containers. I would like to ensure that clicking on the containers does not navigate to another page.

**Additional information:**  
This functionality is similar to the “Expanded View” feature in the Wix Pro Gallery.

 ![Screenshot 2024-12-21 at 12.30.25 PM](https://us1.discourse-cdn.com/wix/original/3X/9/0/90af1ec3810e056d68dbb8efd23905aa72e9e056.png)

---

<div class="post-metadata">

**Author:** ![DeanAyalon](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/deanayalon/32/94633_2.png) [@DeanAyalon](https://forum.wixstudio.com/u/DeanAyalon)\
**Post date:** [December 21, 2024, 8:19am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/2 "2024-12-21T08:19:56Z")

</div>

Page

```js
import wixWindow from 'wix-window-frontend'

$w('#testImage10').onClick(() => {
    // data = whatever data you want to pass to the lightbox
    wixWindow.openLightbox('lightboxName', data)
})

```

Lightbox

```js
import { lightbox } from 'wix-window-frontend'
const data = lightbox.getContext()

```

That’s how you pass data from a page to a lightbox being opened, you can use this for whatever custom functionality you’d like

---

<div class="post-metadata">

**Author:** ![samyak\_prajapati](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samyak_prajapati/32/102090_2.png) [@samyak\_prajapati](https://forum.wixstudio.com/u/samyak_prajapati)\
**Post date:** [December 21, 2024, 11:04am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/3 "2024-12-21T11:04:26Z")

</div>

@DeanAyalon I do not know coding. I pasted your code in it and it didn’t work, so I asked Wix AI which came up with this and I think it’s similar to yours.

**Code for the Page:**

Container ID: # **sketchbox080**  
Image ID (inside the container): # **image80**

```javascript
import { openLightbox } from 'wix-window-frontend';

$w('#sketchbox080').onClick(async () => {
    const imageSrc = $w('#image80').src;
    await openLightbox('lightbox01', { imageSrc });
});

```

**Code for the Lightbox:**

Lightbox ID: # **Lightbox01**  
Image ID (inside the lightbox): # **lightboximage01**  
_(the image inside the lightbox should change as per which container is clicked)_

```javascript
import { lightbox } from 'wix-window-frontend';

$w.onReady(() => {
    // Get the data passed to the lightbox
    const receivedData = lightbox.getContext();
    // Set the image source in the lightbox
    $w('#Lightboximage01').src = receivedData.imageSrc;
});

```

---

<div class="post-metadata">

**Author:** ![codequeen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/codequeen/32/88960_2.png) [@codequeen](https://forum.wixstudio.com/u/codequeen)\
**Post date:** [December 21, 2024, 11:22am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/4 "2024-12-21T11:22:54Z")

</div>

So are you saying you found your solution and it worked?

Or are you still having issues implementing your code?

---

<div class="post-metadata">

**Author:** ![samyak\_prajapati](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samyak_prajapati/32/102090_2.png) [@samyak\_prajapati](https://forum.wixstudio.com/u/samyak_prajapati)\
**Post date:** [December 21, 2024, 12:45pm UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/6 "2024-12-21T12:45:51Z")

</div>

@codequeen No, it’s still not working. I suspect there might be minor issues that could be resolved by someone with coding expertise.

---

<div class="post-metadata">

**Author:** ![codequeen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/codequeen/32/88960_2.png) [@codequeen](https://forum.wixstudio.com/u/codequeen)\
**Post date:** [December 22, 2024, 12:42am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/7 "2024-12-22T00:42:07Z")

</div>

> [@samyak\_prajapati](#):
>
> `lightbox01`

Is the actual name of your lightbox? Like …… My Lightbox.

To open a lightbox via code you need the name of the lightbox not the ID of the lightbox container inside of the lightbox after the lightbox is open.

---

<div class="post-metadata">

**Author:** ![Mark\_Hunte](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mark_hunte/32/100172_2.png) [@Mark\_Hunte](https://forum.wixstudio.com/u/Mark_Hunte)\
**Post date:** [December 22, 2024, 12:45pm UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/8 "2024-12-22T12:45:12Z")

</div>

To illustrate @codequeen answer

For the Page code:

 ![Screenshot 2024-12-22 at 12.31.20](https://us1.discourse-cdn.com/wix/original/3X/4/a/4a117c6ca13157e0bb2da567b913c302fea31083.png)

* * *

For the Lightbox you will need to have an existing Image element inside it…

 ![Screenshot 2024-12-22 at 12.40.09](https://us1.discourse-cdn.com/wix/original/3X/5/d/5da487128d41ab5e3124d33ce89aebd1aae2a2d5.jpeg)

When the code runs that existing images src will be replaced.

 ![Screenshot 2024-12-22 at 12.41.44](https://us1.discourse-cdn.com/wix/original/3X/8/4/8498f280c06a17b30378efcfdb5a200f206b2a71.jpeg)

You will not see the change.  
But not when using preview mode, light boxes can load slowly.

---

<div class="post-metadata">

**Author:** ![samyak\_prajapati](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samyak_prajapati/32/102090_2.png) [@samyak\_prajapati](https://forum.wixstudio.com/u/samyak_prajapati)\
**Post date:** [December 23, 2024, 8:45am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/9 "2024-12-23T08:45:34Z")

</div>

Yes @Mark_Hunte , My Lighbox’s name and its ID, both are same: ‘ **lightbox01** ’. I also have an image element inside it. ( ID **: lightboximagex1** ).

🤩Thanks to you all!!. The code is _mostly_ working now. Clicking any image triggers the lightbox.

However, when I **scroll down** and then click an image, the page automatically scrolls back to the top for some reason. Try it.

**Page link** : [https://sainli21111996.wixstudio.com/betawebsite/process](https://sainli21111996.wixstudio.com/betawebsite/process)

```javascript
import { openLightbox } from 'wix-window-frontend';

$w('#sketchbox080').onClick(async () => {
   
    const imageSrc = $w('#image80').src;
    await openLightbox('lightbox01', { imageSrc });
});

```

For Lightbox

```javascript
import { lightbox } from 'wix-window-frontend';

$w.onReady(() => {
    // Get the data passed to the lightbox
    const receivedData = lightbox.getContext();
    // Set the image source in the lightbox
    $w('#lightboximagex1').src = receivedData.imageSrc;
});

```

---

<div class="post-metadata">

**Author:** ![Pratham](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pratham/32/119586_2.png) [@Pratham](https://forum.wixstudio.com/u/Pratham)\
**Post date:** [December 23, 2024, 10:57am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/10 "2024-12-23T10:57:08Z")

</div>

> [@samyak\_prajapati](#):
>
> However, when I **scroll down** and then click an image, the page automatically scrolls back to the top for some reason. This is happening only in Safari Browser. Try it.

This is happening for some images on Chrome too.

Make sure that the **Link** property for all the images is set to **Not Connected**.

---

<div class="post-metadata">

**Author:** ![samyak\_prajapati](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samyak_prajapati/32/102090_2.png) [@samyak\_prajapati](https://forum.wixstudio.com/u/samyak_prajapati)\
**Post date:** [December 23, 2024, 10:59am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/11 "2024-12-23T10:59:59Z")

</div>

@Pratham What’s is **Link** property? Could you tell me where to find this setting?

---

<div class="post-metadata">

**Author:** ![Pratham](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pratham/32/119586_2.png) [@Pratham](https://forum.wixstudio.com/u/Pratham)\
**Post date:** [December 23, 2024, 11:01am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/12 "2024-12-23T11:01:38Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/3/9/396fa67ecdb6f3afcbafdfab5f91c2eea9e413d8.gif)  
Make sure this is set to **None**.

> **[Wix Editor: Adding a Link to an Element | Help Center | Wix.com](https://support.wix.com/en/article/wix-editor-adding-a-link-to-an-element)**
>
> Add links to elements on your site to help visitors navigate your content, and direct them to relevant and important content.There are many types of links you c

---

<div class="post-metadata">

**Author:** ![samyak\_prajapati](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samyak_prajapati/32/102090_2.png) [@samyak\_prajapati](https://forum.wixstudio.com/u/samyak_prajapati)\
**Post date:** [December 23, 2024, 11:12am UTC](https://forum.wixstudio.com/t/how-to-trigger-a-lightbox-with-specific-content-from-containers/65926/13 "2024-12-23T11:12:12Z")

</div>

@Pratham Yes. **Link** property for all the images is set to **Not Connected**.
