Exit Intent Mobile Pop Up!

Hey All, I came up with a workaround to get the Exit Intent trigger to work on cell phones and tablets!
By default, the trigger does not work on cell phones and tablets. Here is the video, message me if you have any questions - happy to help!

Just in case, here is the script I’ve added to the Custom JS field on the Settings tab of my widget’s settings:

// Function to show the Elfsight widget using the provided API method
function showElfsightPopup() {
  if (typeof widget !== 'undefined' && widget.show) {
    widget.show();
  }
}

// Variables to track scroll position
let lastScrollTop = window.pageYOffset || document.documentElement.scrollTop;
let scrollThreshold = window.innerHeight * 0.35; // 35% of the viewport height

// Detect upward scrolling
window.addEventListener("scroll", function() {
  let currentScroll = window.pageYOffset || document.documentElement.scrollTop;
  if (lastScrollTop - currentScroll > scrollThreshold) {
    showElfsightPopup();
  }
  lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
}, false);

// Detect back button press on mobile
window.addEventListener("popstate", function() {
  showElfsightPopup();
});

// Push a new state into the history to enable back button detection
history.pushState(null, null, window.location.href);

// Detect beforeunload event
window.addEventListener("beforeunload", function() {
  showElfsightPopup();
});

// Detect pagehide event
window.addEventListener("pagehide", function() {
  showElfsightPopup();
});

// Detect visibility change event
document.addEventListener('visibilitychange', function() {
  if (document.visibilityState === 'hidden') {
    showElfsightPopup();
  }
});
3 Likes

Can you share your code you reference in your video?

1 Like

it was under the video on actual youtube , here it is

It is long but give this a spin and let me know, happy to help :slight_smile:

1 Like

Thank you so so much, Dillon! It works!! So appreciate your help.

3 Likes

that makes me incredibly happy! aside from the actual business people making the websites and ads etc… I dont know anyone who uses computers anymore LOL

1 Like

You’re awesome. Do you know how to remove the functionality of the pop-up being triggered upon tapping a new page link in my footer or any links on my page that route to other pages on my site?

try this:

// Function to show the Elfsight widget using the provided API method
function showElfsightPopup() {
if (typeof widget !== ‘undefined’ && widget.show) {
widget.show();
}
}

// Variables to track scroll position
let lastScrollTop = window.pageYOffset || document.documentElement.scrollTop;
let scrollThreshold = window.innerHeight * 0.35; // 35% of the viewport height

// Detect upward scrolling
window.addEventListener(“scroll”, function() {
let currentScroll = window.pageYOffset || document.documentElement.scrollTop;
if (lastScrollTop - currentScroll > scrollThreshold) {
showElfsightPopup();
}
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
}, false);

// Detect back button press on mobile
window.addEventListener(“popstate”, function() {
showElfsightPopup();
});

// Push a new state into the history to enable back button detection
history.pushState(null, null, window.location.href);

// Detect visibility change event
document.addEventListener(‘visibilitychange’, function() {
if (document.visibilityState === ‘hidden’) {
showElfsightPopup();
}
});

2 Likes

You did it again! This works beautifully. Thank you!!

awesome, I’m just a marketing bro who found himself in a depth of ChatGPT coding he had no business being in! Glory be to God on this one LOL!

I’m back. hahah @dillonandrew Do you know how to get the title of the pop-up to pull my font from my website? I have “use font from website” selected with no luck. I’m building my site on Framer so I don’t have an option to add a font url into the css either.

What is the site?

Hey guys :wave:

@dillonandrew A huge thank you for your amazing assistance here! It’s highly appreciated :heart:

@Melody_H I see that you’ve opened a support ticket and our support agent will contact you really soon.

However, if you’d like us to help you here, please share a direct link to the page where your widget is installed. We’ll be happy to check it for you :slightly_smiling_face:

Please Share your complete code Youtube video unavailable

1 Like

Hey there @hamid_waheed :wave:

Here is the code:

// Function to show the Elfsight widget using the provided API method
function showElfsightPopup() {
  if (typeof widget !== 'undefined' && widget.show) {
    widget.show();
  }
}

// Variables to track scroll position
let lastScrollTop = window.pageYOffset || document.documentElement.scrollTop;
let scrollThreshold = window.innerHeight * 0.35; // 35% of the viewport height

// Detect upward scrolling
window.addEventListener("scroll", function() {
  let currentScroll = window.pageYOffset || document.documentElement.scrollTop;
  if (lastScrollTop - currentScroll > scrollThreshold) {
    showElfsightPopup();
  }
  lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
}, false);

// Detect back button press on mobile
window.addEventListener("popstate", function() {
  showElfsightPopup();
});

// Push a new state into the history to enable back button detection
history.pushState(null, null, window.location.href);

// Detect beforeunload event
window.addEventListener("beforeunload", function() {
  showElfsightPopup();
});

// Detect pagehide event
window.addEventListener("pagehide", function() {
  showElfsightPopup();
});

// Detect visibility change event
document.addEventListener('visibilitychange', function() {
  if (document.visibilityState === 'hidden') {
    showElfsightPopup();
  }
});

Give it a go and let me know if it helped :slightly_smiling_face:

Hi, I was exploring useful tips in the Elfsight Community, and clicked your video, but it shows now as unavailable. I understand it is quite a while after you posted your tip, but I would be interested to get to know this option.
Hope you have a fresh link or can restore it,
kind regards,
Ingrid

2 Likes

Hi @Ingrid_van_Waard :wave:

Yeah, unfortunately the video is currently not available, but the solution is still here!

Just enable the Exit Intent trigger, add the script below to the Custom JS field and you’ll witness the magic :wink:

// Function to show the Elfsight widget using the provided API method
function showElfsightPopup() {
  if (typeof widget !== 'undefined' && widget.show) {
    widget.show();
  }
}

// Variables to track scroll position
let lastScrollTop = window.pageYOffset || document.documentElement.scrollTop;
let scrollThreshold = window.innerHeight * 0.35; // 35% of the viewport height

// Detect upward scrolling
window.addEventListener("scroll", function() {
  let currentScroll = window.pageYOffset || document.documentElement.scrollTop;
  if (lastScrollTop - currentScroll > scrollThreshold) {
    showElfsightPopup();
  }
  lastScrollTop = currentScroll <= 0 ? 0 : currentScroll;
}, false);

// Detect back button press on mobile
window.addEventListener("popstate", function() {
  showElfsightPopup();
});

// Push a new state into the history to enable back button detection
history.pushState(null, null, window.location.href);

// Detect beforeunload event
window.addEventListener("beforeunload", function() {
  showElfsightPopup();
});

// Detect pagehide event
window.addEventListener("pagehide", function() {
  showElfsightPopup();
});

// Detect visibility change event
document.addEventListener('visibilitychange', function() {
  if (document.visibilityState === 'hidden') {
    showElfsightPopup();
  }
});
1 Like

O wow, that’s a lot of Javascript. But I will keep a link to it, in case I ever feel I need an exit-intent popup that is important enough to bring in this much script.
Thanks, Max!

2 Likes

Yes, it works for me also, but the popup appears even when I don’t try to exit the page.

For example, when I click the “Buy Now” button.

Any workaround on that?

Otherwise, it is good.

Thanks.

2 Likes

Hi there @user13337 :wave:

Could you please send me a direct link to the page where your widget is installed? I’ll gladly look into this for you :slightly_smiling_face:

Here is the page I have added the popup:

You can see that when you click the “Get it Now!” button, on the price tables, the popup appears.

And also appears when you click the button 'SEE WEBSITE" which is redirecting you on another website, but it is not an exit intent from the visitors but the want to learn more.

And if I visit the page directly through Facebook, which is how my visitors are visiting my page through Facebook ads, then the popup does not apper when you click the back button.

But when you visit the site from a browser, then the popup does apper when you click the back button, so that is good.

Let me know if there is any solution on the above, I really need to use your service and make it work. It is very hard to make a popup appear on mobile. I have tried at least 7-8 of your competitor and only yours work except what I mention above.

Thanks in advance.

1 Like