简体   繁体   中英

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

<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; t=document.title; w = window.screen.width; h = window.screen.height; 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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