Launch Facebook Share Popup at Center of Screen

后端 未结 2 617
别跟我提以往
别跟我提以往 2021-02-02 01:00

The following code works well and launches a facebook popup on the screen, however this popup is not centered.



        
相关标签:
2条回答
  • 2021-02-02 01:36

    See if this works for you:

    <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>
    
    0 讨论(0)
  • 2021-02-02 02:02

    Try this

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


    Or this post with a picture on 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>
    
    

    You can change the image or words
    Size pop-up window
    width=626,height=436
    You can change the size

    0 讨论(0)
提交回复
热议问题