Created
October 25, 2020 00:21
-
-
Save mkdizajn/c46dd47124cdd5650323a0b4562b919a to your computer and use it in GitHub Desktop.
little jquery popup on homepage - only first time - use localstorage to save
This file contains 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
$(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