• Hi Phil,

    This plugin is really a must have. I have a question for your please.

    How to, at age validation (when clicking “OK”), open a second URL in a second tab, in addition to the opening of the main website (this opening must be maintained of course).

    Which file to update (and how)? Your help about this question would be great.

    Thanks a lot for your help,
    Law

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @laucoste,

    I assume you want the other website to be behind the site with age gate on?

    You can add this to your functions.php and it should work, but browsers a pretty strict on popups (or unders) so may not work, not work in future or not work for some users – essentially, I make no promises ??

    Just change “google.com” to whatever you want to open:

    
    add_action('wp_footer', function () {
        ?>
        <script>
            jQuery(document).on('click', '.age-gate-submit-yes', function() {
                var puHref = 'https://google.com'
    
                window.open(window.location.href, "NewSiteWindow");
                window.location.href = puHref;
    
            });
        </script>
        <?php
    }, 1);
    

    Some reading material:

    Where I adapted this from
    https://jamesbachini.com/pop-under-code/

    Some info on opening new windows:
    https://developer.mozilla.org/en-US/docs/Web/API/Window/open

    Thanks
    Phil

    Thread Starter Law

    (@laucoste)

    Hi @philsbury

    Thank you so much for your prompt reply.
    I’ve tested and it is… almost working ??
    When clicking on Yes :
    1- it opens the 2nd link in another tab and the focus is maintained on the main website
    2- the main site is loading (it lasts a bit longer than for a “normal” opening, I mean without any popunder) but maybe just an impression
    3- And here is the KO : it displays again the Age Gate popin

    Would you see any optimization ?
    Kind regards,
    Law

    Plugin Author Phil

    (@philsbury)

    Hmmm, How about this?

    
    add_action('wp_footer', function () {
        ?>
        <script>
            jQuery(window).on('agegatepassed', function(){
                var puHref = 'https://google.com'
    
                window.open(window.location.href, "NewSiteWindow");
                window.location.href = puHref;
            });
        </script>
        <?php
    }, 1);
    

    Thanks
    Phil

    Thread Starter Law

    (@laucoste)

    Hello @philsbury
    Hum, this time it causes a redirection to the 2nd link when clicking on “Yes”, and the main site disappears completely.
    Law

    Plugin Author Phil

    (@philsbury)

    @laucoste – try changing the “NewSiteWindow” to something else. The name allows the browser to reuse it so that could be happening.

    Thanks
    Phil

    Thread Starter Law

    (@laucoste)

    Hi @philsbury
    I just replaced “NewSiteWindow” by “SmthgElse” in the last code snipped but it did not change anything.
    Law

    Plugin Author Phil

    (@philsbury)

    Hi @laucoste, a bit more testing and for me:

    Works in chrome.

    Doesn’t work in Safari or Firefox. Safari definitely blocking the extra window so it’s probably not going to work reliably by the looks of things.

    What is the second window for? It there maybe a work around?

    Thanks
    Phil

    Thread Starter Law

    (@laucoste)

    Hi @philsbury
    Oh, yes I should have precised : I tested in Firefox.
    The second window propose an offer to the visitors.
    OK, I’ll see if I find another code snippet and will share you. The goal is to make it working in FF, Safari and Edge if possible.
    Again, thanks a lot for your help !
    Law

    Plugin Author Phil

    (@philsbury)

    @laucoste How about a popup on the site? Loads of settings available.

    Only real restriction if using an iframe is they can deny cross site embeds, but you could use an image or something too?

    add_action('wp_enqueue_scripts', function () {
        wp_enqueue_script('glightbox', 'https://cdn.jsdelivr.net/gh/mcstudios/glightbox/dist/js/glightbox.min.js', []);
        wp_enqueue_style('glightbox', 'https://cdn.jsdelivr.net/npm/glightbox/dist/css/glightbox.min.css', []);
    });
    
    add_action('wp_footer', function () {
        ?>
        <script>
            jQuery(window).on('agegatepassed', function(){
                var lb = new GLightbox({
                    elements: [
                        {
                            href: 'https://google.com',
                            closeButton: true,
                            // 'title': 'My Title',
                            // 'description': 'Example',
                        },
                    ]
                });
    
                lb.open();
            });
        </script>
        <?php
    }, 1);
    Thread Starter Law

    (@laucoste)

    Hello @philsbury
    Thank you for this other proposition.
    The 2nd site is a subdomain of the main one so it may cause less problem I guess ?
    I’ve applied this “popup” solution and it works fine. I’ll see how our visitors get it over time.
    Thanks for your great help!
    Law

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Add a 2nd URL opening at age validation’ is closed to new replies.