如何使用jquery或php在一天内显示一次FB likebox。我已经完成了弹出,我想在浏览器中保存会话或cookie。所以我可以使事情正常工作。目前我正在使用jquery和php。
<body onload="openOffersDialog();">
<script type="text/javascript" src="popup.js"></script>
<?php
if(!isset($_SESSION['jquery_popup']))
{
$_SESSION['jquery_popup'] = "sessionexists";
echo $_SESSION['jquery_popup'];
?>
<script type="text/javascript">
function openOffersDialog() {
$('#overlay').fadeIn('fast', function() {
$('#boxpopup').css('display','block');
$('#boxpopup').animate({'left':'30%'},500);
});
}
function closeOffersDialog(prospectElementID) {
$(function($) {
$(document).ready(function() {
$('#' + prospectElementID).css('position','absolute');
$('#' + prospectElementID).animate({'left':'-100%'}, 500, function() {
$('#' + prospectElementID).css('position','fixed');
$('#' + prospectElementID).css('left','100%');
$('#overlay').fadeOut('fast');
});
});
});
}
</script>
<div id="overlay" class="overlay"></div>
<!--<a onclick="openOffersDialog();">Click Here To See The PopUp</a>-->
<div id="boxpopup" class="box">
<a onclick="closeOffersDialog('boxpopup');" class="boxclose"></a>
<div id="content">
<h2>Like us on Facebook</h2>
<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fkornerseat&width&height=290&colorscheme=light&show_faces=true&header=true&stream=false&show_border=true&appId=474663095902746" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:290px;" allowTransparency="true"></iframe>
</div>
</div>
<?php
}
?>
答案 0 :(得分:0)
在php代码中按照之前的方式添加你的fb Like按钮
<?php
if(!isset($_SESSION['jquery_popup']))
{
$_SESSION['jquery_popup'] = "sessionexists";
echo '<iframe src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fkornerseat&width&height=290&colorscheme=light&show_faces=true&header=true&stream=false&show_border=true&appId=474663095902746" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:290px;" allowTransparency="true"></iframe>';
}
?>
注意:假设您之前没有销毁会话变量。
答案 1 :(得分:0)
你想要使用一个cookie,简单地将它设置为24小时后死亡,然后检查它是否已经过期,如果它再次显示弹出窗口
的Javascript版本示例function setCookie(cname,cvalue,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname)
{
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++)
{
var c = ca[i].trim();
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}
if(getCookie('jquery_popup') ==""){
setCookie('jquery_popup','sessionexists',1);
//Add code to display popup here
}
PHP方法
if(!isset($_COOKIE['jquery_popup'])){
setcookie("jquery_popup", 'sessionexists', time()+3600*24);
//Add code to display popup here
}