Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  22] [ 5]  / answers: 1 / hits: 17810  / 7 Years ago, wed, january 25, 2017, 12:00:00

I want to show popup just once per session which expire after some time. Can someone help me?



function PopUp(){
$('.home-popup').fadeIn(500);
}

setTimeout(function(){
PopUp();
},1000); // 1000 to load it after 1 second from page load

$('.close-popup-btn').click(function() {
$('.popup').fadeOut(300);
});

More From » jquery

 Answers
18

You could use localstorage for this as well. To set a storage item: localStorage.setItem('myPopup','true'); and to check for it you could do something like this:



var poppy = localStorage.getItem('myPopup');

if(!poppy){
function PopUp(){
$('.home-popup').fadeIn(500);
}

setTimeout(function(){
PopUp();
},1000); // 1000 to load it after 1 second from page load

$('.close-popup-btn').click(function() {
$('.popup').fadeOut(300);
});
localStorage.setItem('myPopup','true');
}

[#59203] Tuesday, January 24, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
teagan

Total Points: 98
Total Questions: 106
Total Answers: 101

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
;