-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexit-intent-popup.js
44 lines (36 loc) · 1.15 KB
/
exit-intent-popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<script>
const CookieService = {
setCookie(name, value, days) {
let expires = '';
if (days) {
const date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toUTCString();
}
document.cookie = name + '=' + (value || '') + expires + ';';
},
getCookie(name) {
const cookies = document.cookie.split(';');
for (const cookie of cookies) {
if (cookie.indexOf(name + '=') > -1) {
return cookie.split('=')[1];
}
}
return null;
}
};
</script>
<script>
const showExitIntentPopup = () => {
document.querySelector('.exit-intent-popup').classList.add('visible');
CookieService.setCookie('exitIntentShown', true, 30);
};
if (!CookieService.getCookie('exitIntentShown')) {
setTimeout(() => {
showExitIntentPopup();
}, 2000); // Display after 2 seconds of page loading
document.querySelector('.exit-intent-popup').addEventListener('click', () => {
document.querySelector('.exit-intent-popup').classList.remove('visible');
});
}
</script>