【发布时间】:2015-10-28 07:57:24
【问题描述】:
我正在为未登录的用户显示一个弹出窗口。我使用 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会帮助你的。
标签: javascript php wordpress popup