问题
I've implemented a code on my page that displays a facebook like popup. I've inserted this code in my website
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js'></script>
<script src="https://gj37765.googlecode.com/svn/trunk/html/[www.gj37765.blogspot.com]jquery.colorbox-min.js"></script>
<link rel="stylesheet" href="https://gj37765.googlecode.com/svn/trunk/html/%5Bwww.gj37765.blogspot.com%5Dfbpopup.css" type="text/css" />
<script type="text/javascript">
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
if (document.cookie.indexOf('visited==false') == -1) {
var fifteenDays = 1000*60*60*24*30;
var expires = new Date((new Date()).valueOf() + fifteenDays);
document.cookie = "visited=true;expires=" + expires.toUTCString();
$.colorbox({width:"400px", inline:true, href:"#mdfb"});
}
});
</script>
<div id="mdfb" style='padding:10px; background:#fff;'>
<h3 class="mdbox-title">Кликни LIKE и стани наш фан да бидеш известен на твојот профил за сите попусти!<center><p style="line-height:3px;" >?</p></center></h3>
<center>
<iframe id="fb-like" src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fshoppingkatalog&width=300&colorscheme=light&show_faces=true&border_color=%23ffffff&stream=false&header=false&height=258" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:300px; height:258px;" allowtransparency="true"></iframe>
</center><p style=" float:right; margin-right:35px; font-size:9px;" >Powered By <a style=" font-size:9px; color:#3B78CD; text-decoration:none;" href="http://www.shoppingkatalog.com">Шопинг Каталог</a></p>
</div>
Now I need to remember when a user clicks like, I need to create cookie or something like that to remember which user has liked my page, and who not. If a user didn't like my page on facebook display the popup again, if the user has pressed like do not show this popup again. Can anybody tell me how to solve this problem?
回答1:
If you want to do it on the client side, look into localStorage
:
To set the value:
localStorage.setItem('liked', 'true');
To get the value:
value = localStorage.getItem('liked');
If you must support older browsers, here's an article on cookies that I found useful.
来源:https://stackoverflow.com/questions/11343687/facebook-popup-remember-when-user-likes