Community X.

Connect with other creators, share ideas, give feedback and get the latest product updates.

Oct 23, 2020
Edited: Oct 23, 2020

Copy source of Iframe from another page to lightbox

Hello everyone,

I'm hoping to get some help with a code snippet that could pull the source used on another page to show on the iframe in a lightbox.

Here's the scenario:

I have a page with a Iframe and a menu with 5-10 buttons below that allows the user to select different views by changing the source URL of the iframe above. I'd like to add a full screen button that would open a lightbox with an iframe that uses the same source as the previous page.

I'm thinking I need to "setitem" the URL source into Wix storage on the main page and then "getitem" from the storage onto the lightbox? I've read through all the Corvid API data about this, but I can't seem to find any code examples that would help me do exactly this. And I've never used Wix storage and don't fully understand the mechanics.

Here's a simplified version of the code used on the original page where the Iframe and menu is located. What should I add to make sure the current Iframe(#html2) Source URL is stored in Wix Storage so it can be pulled in the lightbox?

let clickedBox;

export function box5_click(event) {
    $w('#html2').src = ''
    clickedBox =;

I'll also mention that I'm planning on having about 20 pages with an iframe and menu below, it would be great to have a way so I don't need to create 20 iframes, but I can do it if necessary.

Any help would be greatly appreciated! Thank you.

5 answers3 replies
Best Answer
Oct 23, 2020

Ok, you were right, you need to use wix storage api because the lightbox is an entirely different page, and you cant use $w on elements from another page. so you need to import the local from wix-storage by putting this line on the top of the codes for each of the pages, the main page and the light box.

import {local} from 'wix-storage';

and in your main page in each onClick you need to add a line for the local setItem.

export function box5_click(event) {
    $w('#html2').src = ',-.71&ss=329&play=1&lang=fr&wh=0&vr=0'
    local.setItem('lightBoxSrc', ',-.71&ss=329&play=1&lang=fr&wh=0&vr=0');
    $w('#imageX3').src = ''
    $w('#imageX4').src = ''
    $w('#imageX5').src = ''
    $w('#imageX6').src = ''
    $w('#imageX7').src = ''
    $w('#imageX8').src = ''
    $w('#imageX9').src = ''
    $w('#text12').html = '<p class="p2">'+ $w("#text12").text +'</p>'
    $w('#text30').html = '<p class="p3">'+ $w("#text30").text +'</p>'
    $w('#text32').html = '<p class="p3">'+ $w("#text32").text +'</p>'
    $w('#text34').html = '<p class="p3">'+ $w("#text34").text +'</p>'
    $w('#text37').html = '<p class="p3">'+ $w("#text37").text +'</p>'
    $w('#text38').html = '<p class="p3">'+ $w("#text38").text +'</p>'
    $w('#text39').html = '<p class="p3">'+ $w("#text39").text +'</p>'
    clickedBox =;

and in the lightbox page you need to get the current value of the local storage

import {local} from 'wix-storage';

$w.onReady(function () {
 let value = local.getItem("lightBoxSrc"); // "value"
    $w('#lightboxhtml').src = value;

This Should work. tell me if it did for you.

Oct 23, 2020

Hi Ido, Thanks again for helping me out with another issue!

I don't think this is working, from my limited understanding, it looks like the ID I use for the Iframe when in the lightbox is not available when editing code on the main page. It gives me an error when using the the iframe ID on the main page. Is it possible to make both the lightbox and page communicate so they are using the same references?


Oct 23, 2020

Yes, that works beautifully! Could I please ask one other thing of you?

Is there a snippet I could add that would "setItem" of the Source URL that is shown by default, before a button is clicked? So if a user arrives at the page and before clicking any of the menu buttons they click full screen, they would see the correct URL.

Thank you so much!


you can just use the setItem line with the default url that you want in the $w.onReady function of the main page.

Oct 23, 2020

I did not quite understand what you were trying to do.

Anyway, the simplest way to send information to Lightbox is to use the API.

If you plan to create 20 similar pages, I would recommend that you keep all the information in the database and create dynamic pages. This way allow you create only one page that will use as a template.

You can get the right iFrame's link from the item's dataset and set the link to the iFrame on onReady.

Oct 26, 2020

Thank you Matanya. I think this would be a great idea to save time by setting it up as a dynamic page, however it is out of my comfort zone for writing the code. I have set up dynamic pages with the editor before but with Editor X there are no hover boxes, so everything would need to be coded.

Would you be able to share a snippet of code to show how I can make the menu with hover effects for both the text and images that are connected to a repeater/database? I also need to "setItem" for each click so if the user clicks fullscreen the lightbox will show the correct source. Any help you can provide would be greatly appreciated!

Here's a screenshot of the menu, the first one is currently mouseon. Once clicked, the item should remain highlighted until another item is selected.

Here's a sample of my current code, for one button in the menu, the code is repeated 7 times for each button:

import {local} from 'wix-storage';

let clickedBox;

$w.onReady( function() {
$w("#html2").src = '';
local.setItem('lightBoxSrc', '');
} );

export function box5_click(event) {
    $w('#html2').src = ',-.71&ss=329&play=1&lang=fr&wh=0&vr=0'
    local.setItem('lightBoxSrc', ',-.71&ss=329&play=1&lang=fr&wh=0&vr=0');
    $w('#imageX3').src = ''
    $w('#imageX4').src = ''
    $w('#imageX5').src = ''
    $w('#imageX6').src = ''
    $w('#imageX7').src = ''
    $w('#imageX8').src = ''
    $w('#imageX9').src = ''
    $w('#text12').html = '<p class="p2">'+ $w("#text12").text +'</p>'
    $w('#text30').html = '<p class="p3">'+ $w("#text30").text +'</p>'
    $w('#text32').html = '<p class="p3">'+ $w("#text32").text +'</p>'
    $w('#text34').html = '<p class="p3">'+ $w("#text34").text +'</p>'
    $w('#text37').html = '<p class="p3">'+ $w("#text37").text +'</p>'
    $w('#text38').html = '<p class="p3">'+ $w("#text38").text +'</p>'
    $w('#text39').html = '<p class="p3">'+ $w("#text39").text +'</p>'
    clickedBox =;

export function box5_mouseIn(event) {
    $w('#text12').html = '<a target=""><p class="p2">'+ $w("#text12").text +'</p></a>'
    $w('#imageX3').src = ''

export function box5_mouseOut(event) {
 if ( !== clickedBox){
        $w('#text12').html = '<p class="p3">'+ $w("#text12").text +'</p>'
        $w('#imageX3').src = ''

Editor X

Design your boldest creations.