本文介绍了每次访问仅显示一次弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望每个会话只显示一次弹出窗口,一段时间后过期。有人可以帮帮我吗?
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);
});
推荐答案
您也可以使用localstorage。要设置存储项: localStorage.setItem('myPopup','true');
并检查它,你可以这样做:
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');
}
这篇关于每次访问仅显示一次弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!