web-dev-qa-db-fra.com

Lancer Facebook Partager Popup au centre de l'écran

Le code suivant fonctionne bien et lance une popup Facebook à l'écran, mais cette popup n'est pas centrée.

<script type="text/javascript">
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}

<a href="http://www.facebook.com/share.php?u=<full page url to share" onClick="return fbs_click()" target="_blank" title="Share This on Facebook"><img src="images/facebookimage.jpg" alt="facebook share"></a>

Voici le script qui centre une fenêtre popup: 

    <script type="text/javascript">
 function MyPopUpWin(url, width, height) {
    var leftPosition, topPosition;
    //Allow for borders.
    leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    //Allow for title and status bars.
    topPosition = (window.screen.height / 2) - ((height / 2) + 50);
    //Open the window.
    window.open(url, "Window2",
    "status=no,height=" + height + ",width=" + width + ",resizable=yes,left="
    + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY="
    + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
}
</script>

Quelqu'un peut-il s'il vous plaît mettre à jour le premier script afin qu'il fonctionne en combinaison avec le second script pour faire en sorte que la fenêtre contextuelle se lance au centre de l'écran. (Comme mon expérience en matière de codage est très limitée, je ne sais pas comment faire.) Merci beaucoup. Pia

12
user1736794

Voyez si cela fonctionne pour vous:

<script type="text/javascript">
function fbs_click(width, height) {
    var leftPosition, topPosition;
    //Allow for borders.
    leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
    //Allow for title and status bars.
    topPosition = (window.screen.height / 2) - ((height / 2) + 50);
    var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer', windowFeatures);
    return false;
}
</script>

<!-- Please change the width and height to suit your needs -->
<a href="http://www.facebook.com/share.php?u=<full page url to share" onClick="return fbs_click(400, 300)" target="_blank" title="Share This on Facebook"><img src="images/facebookimage.jpg" alt="facebook share"></a>
32
arturhoo

Essaye ça 



    <script type="text/javascript">
    function fbs_click() {
      u=location.href;t=document.title;window.open(
      'http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),
      'sharer','toolbar=0,status=0,width=626,height=436');return false;
      }
    </script>

    <a href="http://www.facebook.com/share.php?u=<url>" onclick="return fbs_click()" target="_blank">Share on Facebook</a>


Ou ce message avec une photo sur Facebook



    <script type="text/javascript">
    function fbs_click() {
      u=location.href;t=document.title;window.open(
      'http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),
      'sharer','toolbar=0,status=0,width=626,height=436');return false;
      }
    </script>

    <a href="http://www.facebook.com/share.php?u=<url>" onclick="return fbs_click()" target="_blank"><img src="http://originus.samsung.com/us/images/support/facebook-share.png"/></a>

Vous pouvez changer l'image ou les mots 
Taille de la fenêtre contextuelle 
width=626,height=436
Vous pouvez changer la taille 

0
sn ps