Code

Open Lightbox on Pageload

Automatically open Webflow's native lightbox on page load via this Javascript code snippet. Adding a parameter to your website URL allows for the lightbox to automatically be shown on page load.

Open Lightbox on Pageload preview

Automatically open Webflow's native lightbox on page load via this Javascript code snippet. Adding a parameter to your website URL allows for the lightbox to automatically be shown on page load.

How to add it

  1. Give the lightbox button a unique class of btn-video
  2. Link to the parameter in the Javascript code (#video)
  3. Add the Javascript code to your closing body tag of your pages custom code settings

The code

Javascript
                      <!-- Add to closing body tag -->
<script>
$(function() {
        if (document.location.href.indexOf('#video') > 0) {
            $('.btn-video').first().trigger('tap');
        }
    });
</script>

                    

Browse similar code snippets

Categories

Language

More from Corey Moen

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →