Unbounce Answers/Next Steps/Tips & Tricks

How to add a lightbox style window (for privacy policy, rules, terms etc.)

Oli Gardner
posted this on November 19, 2010 04:17 pm

Step A - Create and publish a page containing your privacy policy (rules, terms & conditions etc.)

That's it.  Just build and publish a landing page with your Privacy Policy content.  Be sure to resize the page margins to fit your page content snugly then make note of this page's published URL.


Step B - Add the necessary scripts to your main landing page

  1. Access your page in the Unbounce editor and click the Javascripts button in the bottom left of the editor.
  2. In the bottom left section of the Javascrips box, enable jQuery and jQuery Fancybox.
  3. Click the Add button in the upper left of the dialog to add a new script instance
  4. Name the new instance FancyBox and for placement choose Head
  5. Paste in the following code:
  6. <script type="text/javascript">
    jQuery(function() {
        if (jQuery("a.fancybox.iframe").length) {
          jQuery("a.fancybox.iframe").fancybox({
            'width'           : 450,
            'height'          : 500,
            'autoScale'       : 'false',
            'transitionIn'    : 'elastic',
            'transitionOut'   : 'fade',
            'type'            : 'iframe'
          });
        }
      });
    </script>

    fancybox.png
  7. Customize the width and height fields to match the page you created in Step A
  8. Click Done
     

Step C - Add a link to trigger the lightbox

  1. Drag a new text element onto the page and double click it to open the text editor
  2. Create a link to the Privacy Policy page you created in Step A
  3. In the link dialog, click the Advanced tab
  4. Add iframe fancybox to the Stylesheet classes field
    Screen shot 2012-03-21 at 3.47.03 PM.png 
  5. Click OK, close the text editor then save and republish your page

That should get you rolling!

Note: We are using a jQuery plugin called Fancybox in this example, but any other javascript overlay/dialog/lightbox option would work (there are plenty out there). Check out Fancybox for more information about what you can do with it.

One thing to note is that the lightbox script is very specific and the version used here will only work for text links with the iframe fancybox class.


For help developing a privacy policy tailored to your company and use case, we recommend iubenda

 

Comments

User photo
Vitaliy Levit

Any tips on implementing this for images? There's no access to the HTML.

December 19, 2010 01:26 pm
User photo
Oli Gardner
Unbounce

Hi Vitaliy,

To get it working for an image, add this code into part 1 above:

jQuery(function() {
jQuery("a[target!='_blank'] img").parent('a').fancybox({
    'transitionIn'    : 'elastic',
    'transitionOut'   : 'fade',
    'overlayOpacity'  : 0,
    'hideOnContentClick' : true
  });
});

Then click on the image and set the link property (in the right-hand panel) to be the URL to the full-size image. (Note, that's to load a bigger version of an image. If you want to load a page then insert the URL of the page in the link property field - and then you could add the 'type': 'iframe' to the code like th first example.)

December 20, 2010 01:35 pm
User photo
Vitaliy Levit

Thanks, added. Not dropping the code in the head for some reason. Selected head in script dropdown, ends up at beginning of body.

December 22, 2010 08:35 am
User photo
Oli Gardner
Unbounce

Can you drop an email to support@unbounce.com with your page details etc?

December 22, 2010 06:00 pm
User photo
Steven Hua

This is great -- was able to get the form I wanted to appear via pop-up lightbox when link is clicked. One question, though -- how can I get the popup lightbox to appear automitically (either on page load or after a predetermined amount of time)?

Thanks in advance for any & all info you can provide!

April 13, 2011 01:44 pm
User photo
Carter Gilchrist
Unbounce

Hi Steven, if you're familiar with jQuery and a bit of JavaScript, you could accomplish this by doing the following:

Find the element whose link you want to open when the page first loads. If you know the URL of the link, this is one way to do it:

var link = jQuery("a[href*='google.com']");

That will find all the links that have 'google.com' in the href attribute. You can easily trigger the "click" event on this link to launch the overlay. Next is to wrap a function call in a little setTimeout function to pause for a couple seconds before opening the fancybox:

setTimeout(function() {link.click();},2000);

where 3000 is in milliseconds (so that's 3 seconds). The whole thing would look something like this:

<script>
setTimeout(function() {
var links = jQuery("a[href*='google.com']"); // read more about
link = jQuery(links[0]); // make sure we only activate the first link if more than one are found
link.click();
},3000);
</script>

Hope that helps, let me know how it goes!

April 15, 2011 05:03 pm
User photo
Brandt Wilson

I apologize if this is covered somewhere else and I didn't see it, but I'm trying to figure out how to get a slide show to work. similar to what's discussed above but not exactly. I'm wanting my images to automatically rotate instead of being in an iframe when clicked on.

For example, the html code would be:

<div id="slideshow">
<img src="http://www.website.com/images/image1.jpg">
<img src="http://www.website.com/images/image2.jpg">
</div>

Then my script to call it is

<script type="text/javascript">

$(function() {

$('#slideshow').cycle({ 

fx:    'fade', 

delay: 2000,

timeout: 4000

});

});

</script>

 

How would I alter the java script to make the image rotation work while having a contact form on the page.

This example is using the jQuery Cycle plug in. http://jquery.malsup.com/cycle/

or maybe this set up needs to use the jQuery No Conflict as decribed this post but I'm not understanding correctly how to use the jQuery no conflict keyword:
http://support.unbounce.com/entries/513757-can-i-use-custom-javascr...

Any further direction would be much appreciated.

April 19, 2011 06:00 pm
User photo
CJ Bruce

Is it possible to get this to work with a video embed? When the user clicks on an image, I would like a box to pop up with a YouTube embed that explains more about the feature.

June 23, 2011 08:15 pm
User photo
CJ Bruce

Ok, this might be a crazy work around, but here is what I did to get make it so a user could click on an image, then have that open up a light box with a YouTube embed that autoplays.

First, I changed the size of the box so that it would be the standard YouTube embed (640x390):

jQuery(function() {
if (jQuery("a.fancybox.iframe").length) {
jQuery("a.fancybox.iframe").fancybox({
'width' : 640,
'height' : 390,
'autoScale' : 'false',
'transitionIn' : 'elastic',
'transitionOut' : 'fade',
'type' : 'iframe'
});
}
});

 

Then I created a Custom HTML element that called the image file that I wanted and had the iframe fancybox class so that when a user clicked on it, it would open the YouTube video. For the "href" you have to use the YouTube embed URL instead of the normal URL and to get it to autoplay, you need to add "&autoplay=1". Here is an example of what the link would look like: http://www.youtube.com/embed/UNIQUE_VIDEO_ID?rel=0&autoplay=1

And here is the full custom HTML:

<a class="iframe fancybox" href="http://www.youtube.com/embed/UNIQUE_VIDEO_ID?rel=0&autoplay=1"&... src="https://yoursite.com/images/IMAGE_HERE.jpg"></a>

Now when a user clicks on that image, it will fancybox open to a YouTube embed that autoplays. Pretty cool.

June 23, 2011 09:35 pm
User photo
Oli Gardner
Unbounce
Very cool!!! Thanks for adding that solution in so much detail. #HighFive
June 23, 2011 09:43 pm
User photo
Albert Villalta

Getting back to the original question in the post, I have a few follow questions:

1 - In step 6 you mention add a link in the source code.  How do I that and how do I change the color of the link?

2- When the fancybox pops up in the live version, the box is very small and has scroll bars.  I've included the proper sizes in the jquery code already.

 

Thanks.

October 05, 2011 10:33 am
User photo
Ryan Engley

Hello Albert! These steps should help address your questions:

A) To add the link to your text's source code:

  1. Copy <a class="iframe fancybox" href="http://URL.toyour.other.page">Contest Rules</a> to the clip board (you can change 'Contest Rules' to whatever you want your link text to display)
  2. Open the text editor in Unbounce
  3. Click the 'Source button'
  4. Paste the code from step 1 above into the source code 
  5. Close the text editor

B) To change the colour of your page's links:

  1. First select the page background (You have to click in the page margins to select the background.  Be sure that you are not clicking adjacent to a section in which you have enabled 'Stretch Background to Page Edges' as this prevents you from selecting the background.)
  2. Edit the 'Link Colour' in the properties pane on the right - that's it!

One thing to keep in mind is that changing the link colour is a global change that affects all links on your page.

You can find a video at http://screencast.com/t/971mfkJta that demonstrates the two steps above.

Now, so far as your second question, you should be able to adjust the size of the lightbox by editing the height and width values in the jquery script.  If this isn't working for you, just send us an email to support@unbounce.com and let us know which page you're working on.  We can take a look and see what might be causing the issue.

Cheers! 

October 05, 2011 02:50 pm
User photo
Salim Virani

Hi Oli,

Steps A & B seem to be missing...  Also, would you mind explaining how to do a pop-up video using Fancybox inline rather than iframe?

Thanks

December 05, 2011 08:50 am
User photo
Jacquelyn Ma
Unbounce

Hi Salim - thanks for getting in touch.

In terms of the missing steps in this document, it appears to just be an issue with the knowledge base article being displayed fully. However, full instructions on how to still achieve the lightbox for your page, please refer to the following article:

http://support.unbounce.com/entries/20421057-how-to-add-a-lightbox-...

In regards to the in-line pop-up video, you will want to add this video to a separate landing page and link to it using a text link from your first Unbounce landing page. So in this case, the lightbox functionality that you have already added will be able to affect the link to show the video page as a pop-up video.

I hope this information is helpful. Please don't hesitate to contact us at support@unbounce.com for any further questions.

Cheers,

Jacquelyn M | Unbounce Customer Success

December 05, 2011 03:43 pm
User photo
Veronica Vilchez

My page has several thumb sized images that I want to link to individual unbounce pages with the fancybox effect.  However I cant get them to load properly.  They did work using the example above if I use a text element instead of an image; however when I add the code given by Oli and I use an image it stops working.  This is the script used:

<script type="text/javascript">
jQuery(function() {
if (jQuery("a.fancybox.iframe").length) {
jQuery("a.fancybox.iframe").fancybox({
'width' : 880,
'height' : 630,
'autoScale' : 'false',
'transitionIn' : 'elastic',
'transitionOut' : 'fade',
'type' : 'iframe'
});
}
});
jQuery(function() {
jQuery("a[target!='_blank'] img").parent('a').fancybox({
'transitionIn' : 'elastic',
'transitionOut' : 'fade',
'overlayOpacity' : 0,
'hideOnContentClick' : true
});
});
</script>

 

My other question is:  How should I set the link property on the image.

 

thanks.

December 20, 2011 03:14 pm
User photo
Carter Gilchrist
Unbounce

Hi Veronica, try this code instead:

<script type="text/javascript">
jQuery(function() {
jQuery("a[target='_blank'] img").parent('a').fancybox({
'width' : 880,
'height' : 630,
'autoScale' : 'false',
'transitionIn' : 'elastic',
'transitionOut' : 'fade',
'type' : 'iframe'
});
});
</script>

 And then when you have an image selected, add a link and set the "target" to "New Window _blank":

Screen_shot_2011-12-20_at_4.35.53_PM.png

Let me know how that works!

December 20, 2011 05:25 pm
User photo
Veronica Vilchez

Hi Carter,

Thank you for quick reply.  I tried it and it worked out great!!  

December 20, 2011 05:52 pm
User photo
Carter Gilchrist
Unbounce

Good news! No problem Veronica..

December 20, 2011 06:26 pm
User photo
Veronica Vilchez

Carter, I have one more question.  If I also want to include the FancyBox effect on text links,  How do I need to revise the code so that I can keep it on images as well?

December 23, 2011 09:25 am
User photo
Cass Sapir

Thanks for all the great info.  I am trying to get a button to behave the same way as an image. I've followed the instructions for the botton and tried to make the following alteration but it doesnt work for this.

 

Here's the image script that works...

 

<script type="text/javascript">
jQuery(function() {
jQuery("a[target='_blank'] img").parent('a').fancybox({
'width' : 650,
'height' : 400,
'autoScale' : 'false',
'scrolling' : 'no',
'overlayOpacity' : '0.8',
'overlayColor' : '#000000',
'transitionIn' : 'elastic',
'transitionOut' : 'fade',
'type' : 'iframe'
});
});
</script>

 

and here's the Button script that does not..


<script type="text/javascript">
jQuery(function() {
jQuery(".lp-pom-button a[target='_blank']").fancybox({
'width' : 650,
'height' : 400,
'autoScale' : 'false',
'scrolling' : 'no',
'overlayOpacity' : '0.8',
'overlayColor' : '#000000',
'transitionIn' : 'elastic',
'transitionOut' : 'fade',
'type' : 'iframe'
});
});
</script>

Thanks for all the great advice in these forums!

-Cass

January 05, 2012 09:31 am
User photo
Ryan Engley
Unbounce

Hey Cass - glad to hear you're liking the forums :)

I know Jacquelyn's been chatting about this issue through a support ticket but I wanted to post the answer out here as well in case anyone else has the same question.

In each of the instances of this FancyBox script, what we're playing around with to change the lightbox behaviour are the selector attributes.  If you *really* want to dive into the selector attribute realm of possibilities (exciting, right?), you can read all about them at http://api.jquery.com/category/selectors/.

But without getting too technical, we're playing around with the third line in the script:

jQuery("yada-yada-yada").fancybox({

To have an image trigger a lightbox the snippet would look like this:

jQuery("a[target='_blank'] img").parent('a').fancybox({

This snippet looks for images (img) who's link target is 'New Window (_blank)' to trigger the light box.  See Carter's comment above for a screenshot of those settings.

If you want a button to trigger the lightbox, you need to adjust some of those attributes.  Your script was close but there was a small error in the placement of the lp-pom-button class and computers are fickle, they don't like errors.  

The following line looks for links (a) with the button class (lp-pom-button), who's target is 'New Window (_blank)' to trigger the lightbox.

jQuery("a.lp-pom-button[target='_blank']").fancybox({

Play around with some of the other settings such as turning scroll bars on and off with the 'scrolling' attribute, changing the overlay opacticy with the 'overlayOpacity' attribute, the colour with the 'overlayColor' hex code and the rest.  You can see a little more of what's possible with FancyBox (the plug-in we've used here) at http://fancybox.net/.  A quick note though: there's  a lot you *can* do with this script but as it's a third-party feature, we don't have the resources available to troubleshoot different instances of the script.  Posting in the forums is a great way to look for community feedback if you run into any issues.

Hope that helps!

January 05, 2012 12:54 pm
User photo
Joe Naab

Hey gang. I first wanted to thank everyone for putting this thread together. I added my first lightbox to a text object to show the table of contents of my ebook on the first try. It rocks.

I have a couple of questions for a lightbox that I want to add on the same page that will show a youtube video. I don't have a form on the page so I did steps A & B above for the first lightbox. The questions are:

1. For the second lightbox to show a video, do I need to do create a new script in the js scripts area, give it a new name, and then add the code in step A again? What about step B, no need to repeat?

2. I'm planning on making an image of a "mock" Youtube thumbnail such that when they click on this image, a lightbox opens and plays the video. I'm seeing some scripts above for this, but when I create this image, in the info section for the image, I can only put a URL, not the script. I'm guessing it has something to do with ID or Class fields in the Advanced section, and that one or the other needs to be in the script that I'll create in the js scripts area.

3. If I have one lightbox with a set height and width, but I want a different height and width for the other, is there a conflict? Or is this handled by creating a new js script with it's own name, like "youtube video".

Thanks for any help. I'm thinking if I can figure this out, the "mock" video thumbnail can be smaller than the actual video, saving some landing page real estate. Plus, I think videos in lightboxes are pretty cool.

February 17, 2012 12:40 pm
User photo
Andrew Miller

This fancybox implementation does not seem to scroll on an iPhone or iPad if the page called in the iframe is larger than the fancybox settings (not sure about about other mobile browser / OS combos). We've tried changing the autoScale and height/width options, but to no avail. Any suggestions? Thanks!

If this helps, we're trying to get a desktop-width privacy policy page to work on our mobile unbounce pages as well. 

June 20, 2012 12:19 pm
User photo
Ryan Engley
Unbounce

Hi Andrew - There's a ton you can do with FancyBox but because it's a third-party tool, we don't have the code available for each use case.  You can find all the available permutations on their site at http://fancybox.net/api and to do what you're looking for it seems like you may need to add the scrolling key.  Try adding something like: 'scrolling' : 'auto' 

If you still experience the issue, you may want to reach out in FancyBox's forum where they should be able to provide more expertise.

June 21, 2012 11:24 am
User photo
Sylvain Pastor

Hello, 

I can't figure out how to integrate a fancybox with just text (without having to create another page). I know it is possible because I've seen it here http://fancybox.net/ (inline text) but I just can't figure out how to make it work.

Or is it just not supported by Unbounce?

Any help is greatly appreciated.

thanks

August 20, 2012 03:24 pm
User photo
Jacquelyn Ma
Unbounce

Hi Sylvain - Unfortunately because FancyBox is a third-party tool, as Ryan mentioned in an earlier post, we do not have the code available for each use case. In this case, the challenge is that the in-line text cannot be hidden from the initial page before the FancyBox link is clicked. 

Since this setup is not officially supported by an Unbounce feature, you may want to reach out to reach out to the FancyBox Forum to see if they would be able to provide more expertise on applying this setup via only a custom HTML block on the page. 

August 28, 2012 03:13 pm
User photo
Melanie Kusmik

I have a video iframe on my landing page. I created an iframe fancybox to display text, but when clicked on, it displays beneath the video iframe. How do I tell it to display above it?

September 15, 2012 08:11 am