javascript - 在屏幕中心启动 Facebook 共享弹出窗口

标签 javascript facebook popup xhtml

以下代码运行良好并在屏幕上启动 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=<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>

如何更新第一个脚本,使其与第二个脚本结合使用,从而使弹出窗口在屏幕中央启动?

最佳答案

看看这是否适合你:

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

关于javascript - 在屏幕中心启动 Facebook 共享弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12882689/

相关文章:

javascript - 将数组的值与对象数组的键进行比较

javascript - 保护 javascript [AJAX] 代码?

javascript - session 到期时自动重定向

iOS 应用使用 ShareKit 发布到 Facebook,为什么需要隐私政策?

google-maps - 具有动态自动定位功能的 Google Maps V3 工具提示弹出窗口

javascript - 同一页面内弹出

javascript - 绑定(bind)到文本突出显示

Facebook 缓存不会刷新?

android - 如何在 Android 上获取 Facebook 流和用户配置文件?

javascript - javascript中的自定义弹出窗口