views:

2847

answers:

3

Hi,

I have a facebook iframe application where i have provided a share functionality. I am using this code :

<script>
    function fbs_click()
    {
        u='<?php echo $shareURL;?>';
        t=document.title;
        window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;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://b.static.ak.fbcdn.net/rsrc.php/z39E0/hash/ya8q506x.gif)
     no-repeat top right;
    }
     html .fb_share_button:hover {
      color:#b5b8d3; border-color:#295582; background:#3b5998
      url(http://b.static.ak.fbcdn.net/rsrc.php/z39E0/hash/ya8q506x.gif)
      no-repeat top right; text-decoration:none;
     }
</style>

<a href="http://www.facebook.com/share.php?u=&lt;url&gt;" class="fb_share_button" onclick="return fbs_click()" target="_blank" style="text-decoration:none;">Share</a>

The problem i am facing is that if i pass u to my site url then inside share box title is properly displayed but when posted to my profile, clicking on the link redirects me to outside of my facebook application which i don't want i want it to remain inside facebook page. However if i change u parameter to something like http://apps.facebook.com/app/ then inside share box the title is showing apps.facebook.com and when posted on my profile, clicking on it redirects me inside the facebook application but onto a new tab.

I just want the title should be set according to the value passed and if i click on it on my profile page it should remain inside facebook.

Please help me on this.

Thanks

+1  A: 

Hi,

I have found a solution to this problem you have to change the parameters in the window.open and pass the value as urlencode(i have done in php)

I am attaching the changed code:

1)

  <?php
    $title=urlencode('Facebook Share Platform');
    $image=urlencode('imagepath');
    $summary=urlencode('Check This Out');
    $url=urlencode('http://apps.facebook.com/yourapplication');
   ?>

2)

window.open('http://www.facebook.com/sharer.php?s=100&amp;amp;p[title]=&lt;?php echo $title;?>&amp;p[summary]=<?php echo $summary;?>&amp;p[url]=<?php echo $url; ?>&amp;&p[images][0]=<?php echo $image;?>', 'sharer', 'toolbar=0,status=0,width=626,height=436');

Hope this helps to others who are facing same issue.

Thanks

Pankaj Khurana
+1  A: 

Hi.

Seems like your code it´s working, but there is a little problem with the $image.

It doesn´t show anything in the facebook share page. A little strange because it starting loading the image then it seems that the process it´s not complete.

Do you have any idea ?

pedro
Pankaj Khurana
+1  A: 
def fb_share_knob opts={}
  opts.each { |k,v| opts[k] = CGI.escape(v) if v.present? }
  sharer_url = "http://www.facebook.com/sharer.php?s=100&amp;p[url]=#{ opts[:url] }&p[title]=#{ opts[:title] }&p[summary]=#{ opts[:summary] }&p[images][0]=#{ opts[:image] }"
  <<-FB_SHARE_LINK
  <script type="text/javascript">
    function fbs_click() {
      window.open('#{ sharer_url }','sharer','toolbar=0,status=0,width=626,height=436');
      return false;
    }
  </script>
 <a href="#{ sharer_url }" onclick="return fbs_click()" target="_blank" class="fb_share_link">Share on Facebook</a>
 FB_SHARE_LINK
end

Ruby code. Image load problem: if the image you'd like to share is on your test server make sure it's accessible from outside of your firewall

mitjok

related questions