Last active
September 22, 2022 08:38
-
-
Save herbie4/84cf0bb1e6b6968d982229fc103dd400 to your computer and use it in GitHub Desktop.
Popupmaker plugin: set a auto close time with countdown and option to hide this popup for 1 month, cookie based.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- add this directly into the popup screen of WordPress popupmaker plugin, might need some css styling. --> | |
<div id="close-auto-text"></div> | |
<a class="popmake-close pum-close news-popup-close" href="#" onclick="setPUMcookie();">Click here to hide this popup for 1 month.</a> | |
<code><script>function setPUMcookie() { var CookieDate = new Date; | |
CookieDate.setFullYear(CookieDate.getFullYear()); | |
document.cookie = "pum-4830=true; expires=' + CookieDate.toUTCString() + '; path=/";} | |
var timeLeft = 30; var elem = document.getElementById('close-auto-text'); | |
var timerId = setInterval(countdown, 1000); | |
function countdown() { | |
if (timeLeft == -1) { | |
clearTimeout(timerId); | |
doSomething(); | |
} else { | |
elem.innerHTML = 'This window will close in ' + timeLeft + ' seconds.'; | |
timeLeft--; | |
} | |
} | |
function doSomething() { | |
jQuery('.popmake-close').trigger('click'); | |
} | |
</script></code> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment