Skip to content

Instantly share code, notes, and snippets.

@mkdizajn
Created October 25, 2020 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkdizajn/c46dd47124cdd5650323a0b4562b919a to your computer and use it in GitHub Desktop.
Save mkdizajn/c46dd47124cdd5650323a0b4562b919a to your computer and use it in GitHub Desktop.
little jquery popup on homepage - only first time - use localstorage to save
$(document).ready(function(e){
// local storage var
var ls = localStorage;
var now = new Date();
var old = ( ls.getItem( 'cachetime' ) ) ? new Date( JSON.parse ( ls.getItem( 'cachetime' ) ) ) : new Date( '2000' );
var dis = now - old;
var day = dis / (1000 * 60 * 60 * 24 ) ;
// show popup when EITHER:
// 1) popup never shown before (original first visit)
// 2) or if more then TIME passed after shown
if( day > 20 ){
if( $('body.home').length ) $.fancybox.open({
src : '#popupnewsletter',
type : 'inline',
animationEffect : 'zoom-in-out',
width: "500",
height: "320",
});
// popup shown
ls.setItem( 'cachetime', JSON.stringify( new Date() ) ) ;
}
// POPUP WINDOW - TRIGGER NEWSLETTER @HOMEPAGE
$( '[name="mc-embedded-subscribe-form"] [type="submit"]' ).on('click', function(e){
ls.setItem( 'cachetime', JSON.stringify( new Date() ) ) ;
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment