Lightbox Open on load from certain referrers

Hi,

I am trying to implement some code that automatically opens a lightbox when visitors come from a certain referrer. I’m having trouble as I’m not sure exactly how the X lightbox shortcode works. The page is in the secure form and the code is below. Any guidance or help would be greatly appreciated. Thanks in advance!

if (document.referrer.indexOf('facebook.com') >= 0){
jQuery(document).ready(function($){

setTimeout(function() {
$('#x-lightbox-1').click();
}, 5000);
});
}

Nevermind. I made it work by changing the selector. Thanks so much. Sorry to waste your time.

jQuery(document).ready(function($){

setTimeout(function() {
    $('.x-img-link').click();
}, 100);
});

Hello @Brad_B_1,

We are just glad that you have figured it out a way to correct the said issue.
Thanks for letting us know!

Best Regards.

Sorry for the false alarm. I am having issues with this again and I’m hoping you can help. The page in question has a video in a lightbox. The button to the lightbox is hidden. I have added the following code so that only some visitors see the lightbox on load. For some reason, it still isn’t working. Any idea what could be wrong? Thanks in advance!

The ifno is in the secure form, and the code I am using is:

if (document.referrer == 'http://l.ead.me/bayWpx'){
 $(window).on('load',function(){
 $('.x-img-link').click();
}

Hi @Brad_B_1,

The problem is the referrer, this document.referrer returns blank. Please check his https://coderwall.com/p/7a09ja/no-referer-after-redirect-solved. This means that the redirect from http://l.ead.me/bayWpx doesn’t have a referred or empty due to the nature of how redirection is implemented.

I recommend contacting the author of that URL to see what’s best. And I also tried that code with different URL and it works since the referred is properly set.

This is when I click that link from your code

And this is when I click the link from your secure note (it’s a valid referrer since it’s not a redirect).

Thanks!

Great. Thanks so much. Appreciate it!

I tried to create a redirect instead, but the documnt.referrer is also blank. Is there a simple way for me to create a redirect that keep the referrer info intact? Thanks again!

Hi There,

Please try adding the varriable to your website URL when redirect.

Something likes this:

https://www.yourwebsite.com/?my_redirect=1

Then change the if condition to: document.referrer.indexOf('my_redirect') >= 0

Hope it helps :slight_smile:

Thanks so much! Sorry to keep asking questions… I added the variable to the redirected URL and changed the code to:

if (window.location.href.indexOf("?qr_lightbox") > -1){
 $(window).on('load',function(){
 $('.x-img-link').click();
}

However, the lightbox still isn’t loading when I visit the page using /software. Am I missing something else? Thanks so much again!!

Hi,

I checked your page and didn’t see any lightbox enabled for an image so there is nothing to click with this command.

 $('.x-img-link').click();

While we are happy to help with the occasional quick tweak here or there, we are well into the custom development realm, which is outside the scope of support we can offer. If you need more in depth changes, you may wish to consult with a developer. X is quite extensible with child themes, so there are plenty of possibilities. Thanks for understanding.

Thanks for your help. Appreciate it!

Thanks for understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.