简体   繁体   English

Facebook分享链接问题

[英]Facebook share link problem

I have a classifieds section. 我有一个分类部分。 I want to allow users to share a particular ad from a page. 我想允许用户共享页面中的特定广告。 I have created a page that allows a user to print the ad out, so I used that page as the actual share link. 我创建了一个页面,允许用户打印广告,因此我将该页面用作实际的共享链接。 The problem is, that when I use the script that opens it's own smaller window, no matter what I specify as the link it shares the entire page, not the URL I specify. 问题是,当我使用打开的脚本时,它是一个较小的窗口,无论我指定为什么链接,它都共享整个页面,而不是我指定的URL。 Here is the code I am using. 这是我正在使用的代码。

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

if I use the following code, it works just as it should, but it won't open in a new smaller window, it goes to the facebook site and away from my site. 如果我使用以下代码,它将按预期运行,但不会在新的较小窗口中打开,它会转到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>

Thanks for you help! 感谢您的帮助!

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

The above opened it for me in the same size as the screen resolution. 上面的内容为我打开了与屏幕分辨率相同的尺寸。 Try it out and let me know. 试试看,让我知道。

I actually figured it out. 我真的想通了。 Put the script in the head of the document, and just referenced the function with parameters to get the desired result. 将脚本放在文档的开头,然后使用参数引用该函数以获取所需的结果。 Worked perfectly. 工作完美。

In the head: 在头上:

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

And then for each ad: 然后针对每个广告:

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

Worked like a dream. 像梦一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM