2012-10-14 30 views
12

Mã sau hoạt động tốt và khởi chạy cửa sổ bật lên facebook trên màn hình, tuy nhiên cửa sổ bật lên này không được căn giữa.Khởi chạy Facebook Chia sẻ Cửa sổ bật lên tại Trung tâm Màn hình

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

Đây là kịch bản mà các trung tâm một cửa sổ popup:

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

Ai đó có thể vui lòng cập nhật kịch bản 1 để nó hoạt động kết hợp với kịch bản thứ 2 là kết quả trong cửa sổ bật lên bật lên ở giữa màn hình. (Như kinh nghiệm của tôi với mã hóa là rất hạn chế tôi không biết làm thế nào để làm điều này.) Cảm ơn đống. Pia

Trả lời

32

Xem nếu điều này làm việc cho bạn:

<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

Điều đó hoạt động hoàn toàn hoàn hảo! Bạn là một coder siêu thiên tài cuối cùng uber người mát mẻ. Cảm ơn. :) Pia @arturhoo – user1736794

+0

Vui mừng khi biết điều đó phù hợp với bạn! – arturhoo

+0

Chính xác những gì tôi đang tìm kiếm - cảm ơn bạn rất nhiều! – Ingusmat

0

Hãy thử điều này



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


Hoặc bài này với một hình ảnh trên 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> 

Bạn có thể thay đổi hình ảnh hoặc các từ
Kích thước cửa sổ bật lên w indow
width=626,height=436
Bạn có thể thay đổi kích thước

Các vấn đề liên quan