Cookie-Controlled Popup
Professional-grade popup management. This script uses persistent browser cookies to track visitor interactions, ensuring that high-impact windows like newsletter signups or important alerts are only displayed once per unique user session.
Persistent Tracking Logic
Unlike simple session-based scripts which reset when the browser closes, this version writes a persistent cookie with an expiration date. This ensures the script "remembers" users even if they return days later, making it ideal for marketing campaigns.
Copy the Script
<script>
// Helper function to read cookie value
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
function checkPopup() {
// Check if cookie exists
var visited = getCookie("seen_promo");
if (!visited) {
// 1. Show the popup (replace URL and params as needed)
window.open('https://www.google.com', 'promoWin', 'width=500,height=400');
// 2. Set the cookie so it doesn't show again
var date = new Date();
date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000)); // Expires in 30 days
document.cookie = "seen_promo=true; expires=" + date.toUTCString() + "; path=/";
}
}
// Run logic when page finishes loading
window.onload = checkPopup;
</script>
Frequently Asked Questions
The duration is determined by the 'expires' attribute. You can set it for 30 days, a year, or even indefinitely to prevent the popup from ever appearing again for that user.
If cookies are cleared, the script will no longer find the 'shown' flag and will treat the user as a first-time visitor, triggering the popup once more.
Yes. Simply use different cookie names (e.g., 'promo1', 'promo2') for each unique popup script you implement on your site.