How to open a lightbox on page load if url equals

2019-09-20 15:49发布

问题:

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>

回答1:

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/