Search code examples
javascriptlightboxgoogle-tag-managerfeatherlight.js

How to open a lightbox on page load if url equals using google tag manager


The title pretty much says it. I would like to show a lightbox on page load only if the url is www.example.com/#popup versus www.example.com

If this could be accomplished with google tag manager that would be grand

I've see bits and pieces of this but I'm having trouble piecing it all together.

HTML:

<a href="#" data-featherlight="#mylightbox">Open element in lightbox</a> 
<div id="mylightbox">This div will be opened in a lightbox</div>

Solution

  • if (window.location.hash === "#popup") {
        $.featherlight("#mylightbox");                   
    }
    

    See https://github.com/noelboss/featherlight/#manual-calling-of-featherlight

    Fiddle Shows manual lightbox open call. http://jsfiddle.net/fm9wp96r/