• Resolved damelco

    (@damelco)


    https://example.com/somepage/?doc=003

    <a id="doc_003" class="fancybox-pdf" href="/somepage/doc003.pdf">
     
    <script>
    var urlParams = new URLSearchParams(window.location.search);\n";
    var param1 = urlParams.get('doc');\n";
    document.getElementById('doc_' + param1).click();
    </script>
    

    the popup works fine when the link gets an actual ‘mouse-click’. just cannot figure out how to get a script-click to trigger the popup. I must be approaching this wrong?

    thoughts?

    -DJ

    • This topic was modified 4 years, 7 months ago by damelco.
    • This topic was modified 4 years, 7 months ago by damelco.
    • This topic was modified 4 years, 7 months ago by damelco.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Maybe remove those \n"; at each line ending?

    Thread Starter damelco

    (@damelco)

    sorry, that section is inserted from php and forgot to remove them when entering this example?

    <a id="doc_003" class="fancybox-pdf" href="/somepage/doc003.pdf">
     
    <script>
    var urlParams = new URLSearchParams(window.location.search);
    var param1 = urlParams.get('doc');
    document.getElementById('doc_' + param1).click();
    </script>

    but it sounds like you would expect this “method” to work, huh? I’ll revisit it again.

    thanks

    -DJ

    Can you share a link to your site so I can see it live? It’d help to see browser console error messages…

    Thread Starter damelco

    (@damelco)

    access would be problematic, being this code is inside a member only library.

    however, I think I see why it doesn’t work.
    I added a bit of a wait and it seems to be good, albeit not a very elegant solution.

    jQuery(document).ready(function($){
        var urlParams = new URLSearchParams(window.location.search);
        var param2 = urlParams.get('doc');
        setTimeout(
            function() {
                jQuery('#libitem_' + param2.padStart(3, '0') + '_a').trigger('click');
        }, 3000);
    });

    is there a event or var I can monitor when easy fancybox is done loading/processing the DOM … akin to a ‘fancybox-done’, so to speak?

    thanks again Rolf for the excellent plugin and support!

    -DJ

    • This reply was modified 4 years, 7 months ago by damelco.

    Ah yes, if your code runs before the fancybox code (in the footer) then you need this timeout you are using now. There is currently no event like “fancybox-ready” but I will certainly add this to the feature requests!

    Your alternatives (to your timeout solution) are:
    1. Place your code in the theme’s footer.php file below the wp_footer() call. Or…
    2. Go to Settings > Media and check the option “Move scripts from footer to theme head section” in the Theme & plugins compatibility section. Or…
    3. Get the advanced plugin and set the option “Open on page load: Link with ID matching URL hash” in the Auto-popup section and then convert the way to link from https://example.com/somepage/?doc=003 to https://example.com/somepage/#doc_003 (for example)

    Or you can wait for the “fancybox-ready” event to arrive (probably) in the next release ??

    Thread Starter damelco

    (@damelco)

    awesome … I’ll keep my eye on the change-log.

    thanks again!

    -DJ

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘js triggered popup’ is closed to new replies.