2011-01-21 243 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> 

工作就像一个梦。