DEV Community

Cover image for Display a modal when users leave website

Display a modal when users leave website

Phuoc Nguyen on December 27, 2023

Retaining customers on a website can be challenging, but there's a trick that works like a charm: showing a subscription modal when they're about t...
Collapse
 
reinerknudsen profile image
Reiner Knudsen

One of the functions I really hate on websites. „Oh, you are leaving. Wait! Let me sell you something first.“
People should create interesting and inviting sites rather than pull the desperate trigger when people leave. This is never going to make it on one of my sites.

Collapse
 
phuocng profile image
Phuoc Nguyen

I completely agree with you! It never happens on my sites! That's why I added a "Good practice" section at the end.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

As a user of the internet if anyone tries to stop me leaving I will never come back. Do not annoy your customers

Collapse
 
cezarymazur profile image
Cezary Mazur

Not the best idea but sometimes clients want that, good article!😊

Collapse
 
phuocng profile image
Phuoc Nguyen

Thank you!

Collapse
 
tr11 profile image
Tiago Rangel

btw, the demo isn't working for me. (latest version of Firefox on Win 11 insider)

Collapse
 
phuocng profile image
Phuoc Nguyen

It's nice catch. Let me figure it out why it doesn't work.

Collapse
 
martinfjant profile image
Martin Falk Johansson

Do not do this.

Collapse
 
manchicken profile image
Mike Stemle

Fo security reasons, cookies in JavaScript should be avoided.

Collapse
 
tr11 profile image
Tiago Rangel

yeah, you should mostly use localStorage, it's much easier to work with

Collapse
 
for_mdtariqul profile image
Md Tariqul

thanks !