2012-10-14 15 views
12

Der folgende Code funktioniert gut und startet ein Facebook-Popup auf dem Bildschirm, aber dieses Popup ist nicht zentriert.Launch Facebook Share Popup im Zentrum des Bildschirms

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

Hier ist das Skript, das ein Popup-Fenster zentriert:

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

Kann jemand bitte das erste Skript aktualisieren, so dass es in Kombination mit dem zweiten Skript arbeitet führen im Popup-Fenster in der Mitte des Bildschirms starten. (Da meine Erfahrung mit der Codierung sehr begrenzt ist, weiß ich nicht, wie man das macht.) Vielen Dank. Pia

Antwort

32

sehen, ob das funktioniert für Sie:

<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

Das funktioniert absolut perfekt! Du bist ein super Genie Coder ultimative über coole Person. Vielen Dank. :) Pia @arturhoo – user1736794

+0

Gut zu wissen, dass es für Sie gearbeitet hat! – arturhoo

+0

Genau das, was ich gesucht habe - vielen Dank! – Ingusmat

0

Versuchen Sie, diese



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


Oder diesen Beitrag mit einem Bild auf 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> 

Sie das Bild ändern kann oder Wörter
Größe Pop-up w indow
width=626,height=436
Sie können die Größe ändern