var showPopupDelay = 2000; var showPopupLiveTime = 1; function showPopup() { setTimeout(function() { $('#popup').modal('show'); }, showPopupDelay); } function setPopupDisplayTime() { try { localStorage.setItem('popupLastShown', new Date().getTime().toString()); } catch (e) { console.error('Local storage is not available:', e); } } function shouldShowPopup() { try { const lastShown = localStorage.getItem('popupLastShown'); if (!lastShown) { return true; } const currentTime = new Date().getTime(); const timeDifference = currentTime - parseInt(lastShown, 10); const daysSinceLastShown = timeDifference / (1000 * 3600 * 24); const daysBeforeShowingAgain = showPopupLiveTime; return daysSinceLastShown >= daysBeforeShowingAgain; } catch (e) { console.error('Error checking popup display condition:', e); return true; } } function handlePopupDisplay() { if (shouldShowPopup()) { showPopup(); setPopupDisplayTime(); } } $(document).ready(function(){handlePopupDisplay();});