我正在顯示未登錄的用戶的彈出窗口。我使用javascript和PHP執行此操作。在刷新時顯示彈出框和重置定時器
<?php
if ((is_single() || is_front_page() || is_page())
&& !is_page('login') && !is_page('register') && !is_user_logged_in()){
echo'<div class="overlay-bg">
</div>
<div class="overlay-content popup3">
<h1>You must login or Register to view this site. do_shortcode("[sp_login_shortcode]");</h1>
</div>';
}
?>
Javascript代碼如下
$(document).ready(function(){
// function to show our popups
function showPopup(whichpopup){
var docHeight = $(document).height(); //grab the height of the page
var scrollTop = $(window).scrollTop(); //grab the px value from the top of the page to where you're scrolling
$('.overlay-bg').show().css({'height' : docHeight}); //display your popup background and set height to the page height
$('.popup'+whichpopup).show().css({'top': scrollTop+20+'px'}); //show the appropriate popup and set the content 20px from the window top
}
// function to close our popups
function closePopup(){
$('.overlay-bg, .overlay-content').hide(); //hide the overlay
}
// timer if we want to show a popup after a few seconds.
//get rid of this if you don't want a popup to show up automatically
setTimeout(function() {
// Show popup3 after 2 seconds
showPopup(3);
}, 4000);
});
我想5分鐘,首次訪問者,當他訪問該網站後,顯示彈出。但是當同一個訪客刷新頁面或將來再來時,我想在5分鐘後立即顯示彈出窗口。
我該如何在上面的代碼中實現這一點。請幫忙。
謝謝
'cookies'會幫你。 –