2012-10-14 6 views
12

Il seguente codice funziona bene e lancia un popup di Facebook sullo schermo, tuttavia questo popup non è centrato.Avvia Facebook Condividi Popup al Center of Screen

<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> 

Ecco lo script che centra una finestra pop-up:

<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> 

Qualcuno può aggiornare il primo script in modo che funziona in combinazione con il secondo script per provocare nella finestra popup che si avvia al centro dello schermo. (Dato che la mia esperienza con la codifica è molto limitata, non so come farlo.) Grazie mille. Pia

risposta

32

vedere se questo funziona per voi:

<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> 
+9

Che funziona perfettamente! Sei un super genio coder, una persona super cool per eccellenza. Grazie. :) Pia @arturhoo – user1736794

+0

Felice di sapere che ha funzionato per te! – arturhoo

+0

Esattamente quello che stavo cercando anche io - grazie mille! – Ingusmat

0

Prova questa



    <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> 


O questo post con una foto su 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> 

È possibile modificare l'immagine o parole
Dimensioni pop-up w indow
width=626,height=436
È possibile modificare la dimensione

Problemi correlati