How to Embed Videos in a Lightbox?


#1

I want to add a lightbox to show up a youtube video.
I want the visitors to click on an image and it would pop up a lightbox with the video on autoplay.

how can i do this?


#2

Hey Rodrigo

What you’ll want to do is grab the embed URL from Youtube. If your viewing the video on youtube it can be found right below under the Share > Embed tab:

Copy just the URL within the embed code and paste that into Unbounce as your image link.

Now Navigate to your javascripts box and paste in the following code:

<br /> $('#lp-pom-image-25 a').fancybox({ <br /> type: 'iframe', <br /> width: 840, <br /> height: 480 <br /> }); <br /> }); <br /> </script>```   
 
Replace 'lp-pom-image-25' with the ID of your image (leave in the 'a' following the ID)   
 
If you want your video to autoplay append the following to your youtube URL:   
 
?autoplay=1   
 
Your updated link will look something along the lines of:   
 
[https://www.youtube.com/embed/DlJEt2KU...](https://www.youtube.com/embed/DlJEt2KU33I?autoplay=1)   
 
That should do it! Let me know if you run into issues :)

#3

Hey there!
This is my landing page : http://conheca.inforbyte.com.br

I followed your steps, but something went wrong.
I added the embbed link to the image, and set the target to ‘not set’

After that i added the javascript to my page and replaced the the image id to my image id lp-pom-image-187.

when i go to the preview, the lightbox comes up, but no video comes in it…

Any ideas on what i could be missing?


#4

Hi Rodrigo - you’ll need to publish out and go to the live page to see the change. It won’t show in the preview.


#5

Hey Rodrigo

It looks like everything is setup as it should be. Keep in mind that lightboxes don’t display the content within ‘preview’. If you view the changes on the live published page it should render there.

Let me know if your still encountering issues.


#6

hey there, i just realized that it works fine on the published preview!
Sorry about that!

Great help from you guys, Thanks!!


#7

Hi guys, 

i really need that to work, but in my case, I need it for 4 images to pop. Is there any way I can optimize this script to work? Check out the “Perfil para mœsicos” on my landing page http://novo.formband.com.br. I need each screen to open full. Is there any way?


#8

Hi Mario, 

You should be able to target multiple elements by adding them all in, separated with a comma. For example, instead of: 
(’#lp-pom-image-25 a’)

You would use: 
(’#id-pom-image-25 a, #id2 a, #id3 a’)

Give that a try and let me know how it works out for you!


#9

same exact question for me, Juan! So guys, what should we do? =)


#10

Hi Juan! 
Sorry about this, but can you clarify exactly what you’re looking to do? Just want to make sure I have a clear understanding before I put my foot in my mouth and recommend something that doesn’t work.
Thanks!


#11

Ok Justin, no worries, I would try to be more clear. I _m just building my landing page: http://unbouncepages.com/quincename/ and I _m embedding a youtube video. The problem starts when you make a click to play the video and the lightbox size opens “HUGE” of the size of the screen, so people CAN _T close the video and return easily to the landing page. It happens the same with the example that that Johnny gave us: https://www.youtube.com/embed/DlJEt2KU… 

And what I want to achieve is the same type of lightbox that Rodrigo has in his landing page: http://conheca.inforbyte.com.br/ that opens much smaller and you can close it really easy and return to the landing. 

Cheers!


#12

What if I need to allow fullscreen view? What should I add to the javascript code?
Tks a lot!


#13

Hi Justin, any news for this? Tks!


#14

Hello Juan,

Looking at the code provided earlier in the message chain it looks like you may be able to specify the dimensions of the lightbox via the width and height.  Just make you keep the dimensions proportionate :slight_smile:

<br> $('#lp-pom-image-25 a').fancybox({ <br> type: 'iframe', <br> width: 840, <br> height: 480 <br> }); <br> }); <br> </script>```  
 
Hope that helps, Juan!&nbsp; Also consider hosting your video on Wistia!&nbsp; They have a free account and it is an overall higher quality experience and avoids ads etc.&nbsp; not to mention you can get some quality data on the effects of your video.  
 
Best of luck,  
 
Joe Faillace

#15

Hi Joe, thanks for your support! I _ve already tried with other dimensions but it still doesn _t work. With your recommendation I _ve changed to wistia and it already improved. Thanks!!


#16

Hello!
If I don _t want the lightbox to open really big as the example that Johnny gave us: https://www.youtube.com/embed/DlJEt2KU… 
But I want to open as the landing page of Rodrigo that is with a much smaller size http://conheca.inforbyte.com.br/
What should I do?


#17

UPDATE: 

We’ve released a new feature into beta that allows you to build/launch your lightboxes directly within the page builder itself. This new release will allow you to add images, videos, forms and even scripts (such as Google Maps) to your lightboxes. 

Go check it out and sign up for the beta  here


#18

What if you want to do the same but only using linking text and not an image?


#19

I’m very much interested in this as well. How Can you keep the full-screen controls on youtube videos with the script.