web-dev-qa-db-ja.com

画面の中央でFacebook共有ポップアップを起動

次のコードは適切に機能し、画面上に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;}
<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>

ポップアップウィンドウを中央に配置するスクリプトは次のとおりです。

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

誰かが最初のスクリプトを更新して、2番目のスクリプトと組み合わせて機能し、画面の中央でポップアップウィンドウが起動するようにしてください。 (私のコーディングの経験は非常に限られているので、これを行う方法がわかりません。)どうもありがとう。ぴあ

12
user1736794

これがあなたのために働くかどうか見てください:

<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

これを試して



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


または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>

画像や言葉を変更できます
サイズポップアップウィンドウ
width=626,height=436
サイズを変更できます

0
sn ps