Display Popup with facebook page for users, show once every 7 days

Asked

Viewed 96 times

0

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/pt_BR/sdk.js#xfbml=1&version=v2.10";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-like" data-href="https://www.facebook.com/www.maroclub.net/" data-width="150" data-layout="standard" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>

This is the facebook code, a button to like page, I want to display after 10 seconds the user open the page. If you know any function that checks if he has already liked the page please add, why in that case it would only display if the user hasn’t liked yet what would be best.

1 answer

0


The function that checks if he has liked I do not know!

Library

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 

HTML Modal

<div id="myModal" class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">Modal</h4>
            </div>
            <div class="modal-body">
                <div id="fb-root"></div>
                <script>(function(d, s, id) {
                  var js, fjs = d.getElementsByTagName(s)[0];
                  if (d.getElementById(id)) return;
                  js = d.createElement(s); js.id = id;
                  js.src = "//connect.facebook.net/pt_BR/sdk.js#xfbml=1&version=v2.10";
                  fjs.parentNode.insertBefore(js, fjs);
                }(document, 'script', 'facebook-jssdk'));</script>

                <div class="fb-like" data-href="https://www.facebook.com/www.maroclub.net/" data-width="150" data-layout="standard" data-action="like" data-size="small" data-show-faces="true" data-share="true">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
            </div>
        </div>
    </div>
</div>

SCRIPT - comments in the code

//verifica se o cookie não existe ou se já está expirado 
if (document.cookie.indexOf("visita=") < 0) {  
    //abre o modal em 10 segundos
    setTimeout(function() {
        $('#myModal').modal();
    }, 10000);
   //grava cookie
   var date = new Date();
   //expira em 7 dias
   date.setTime(date.getTime()+(7*24*60*60*1000));
   var expires = "; expires="+date.toGMTString();

   document.cookie = "visita=realizada"+expires+"; path=/";

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.