2011-01-21 129 views
1

我有分類欄目。我想讓用戶從一個頁面分享特定廣告。我創建了一個允許用戶打印廣告的頁面,因此我使用該頁面作爲實際的共享鏈接。問題是,當我使用腳本打開它自己的小窗口時,無論我指定哪個鏈接共享整個頁面,而不是我指定的URL。這是我正在使用的代碼。Facebook共享鏈接問題

<script>function fbs_click() {u='http://<?php echo $_SERVER['SERVER_NAME']; ?>/classifieds/printAd.php?AdID=<?php echo $row_rsAds['AdID']; ?>';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><style> html .fb_share_button { display: -moz-inline-block; display:inline-block; padding:1px 20px 0 5px; height:15px; border:1px solid #d8dfea; background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right; } html .fb_share_button:hover { color:#fff; border-color:#295582; background:#3b5998 url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right; text-decoration:none; } </style> <a rel="nofollow" href="http://www.facebook.com/share.php?u=<;url>" class="fb_share_button" onclick="return fbs_click()" target="_blank" style="text-decoration:none;">Share</a> 

如果我使用下面的代碼,它只是因爲它應該,但它不會在一個新的小窗口中打開,它進入Facebook網站,並從我的網站了。

<a href="http://www.facebook.com/share.php?u=http://<?php echo $_SERVER['SERVER_NAME']; ?>/classifieds/printAd.php?AdID=<?php echo $row_rsAds['AdID']; ?>" onclick="return fbs_click()" target="_blank">Share on Facebook</a> 
<a class="boldbuttonsFaceBook" href ="http://www.facebook.com/sharer.php?u=http%3A%2F%2F<?php echo $_SERVER['SERVER_NAME']; ?>%2Fclassifieds%2FprintAd.php?AdID=<?php echo $row_rsAds['AdID']; ?>&t=Dragboats.com Classifieds"><span>SHARE ON FACEBOOK</span></a> 

感謝您的幫助!

回答

0

function fbs_click(){ u = link; t = document.title; w = window.screen.width; h = window.screen.height; window.open(link,'sharer','menubar = 1,resizable = 1,width ='+ w +',height ='+ h + '25'); }

上面打開它對我來說與屏幕分辨率相同。試試看,讓我知道。

+0

謝謝!實際上我發現它的方式稍有不同。 – dragboatrandy 2011-01-21 05:22:13

0

我其實已經想通了。將腳本放在文檔的頭部,並用參數引用函數以獲得所需的結果。完美工作。

在頭:

<script> 
function fbs_click(u, t) { 
    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> 

<style> 
html .fb_share_button { 
    display: -moz-inline-block; 
    display:inline-block; 
    padding:1px 20px 0 5px; height:15px; 
    border:1px solid #d8dfea; 
    background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right; 
} 
html .fb_share_button:hover { 
    color:#fff; border-color:#295582; 
    background:#3b5998 url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top right; 
    text-decoration:none; 
} 
</style> 

然後爲每個廣告:

<a rel="nofollow" href="#" class="fb_share_button" onclick="return fbs_click('http://<?php echo $_SERVER['SERVER_NAME']; ?>/classifieds/printAd.php?AdID=<?php echo $row_rsAds['AdID']; ?>', 'Dragboats.com Classified Ad')" target="_blank" style="text-decoration:none;">Share</a> 

工作就像一個夢。