3

I want to make a button that shares links in this form:

http://example.com/#anchor

but when i click it, it shares only

http://example.com

How could I make it share what I want?

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113

3 Answers3

4

This is very simple; your URL string you want to share should be like this: http://www.domain.com/hello.html%23myanchor

The %23 will be transformed by Facebook into a #.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
2

Your question is not very detailed and it's not easy to understand exactly what it is you're asking for..

Since the share functionaliy was deprecated I assume that you are talking about the Like button. As you can see in that page you can put what ever url you want into the "URL to Like" field, then click the "Get Code" button and use that code in your page.

You can put the code in any page, so if your page is: "example.com/#anchor" you can still have the button like "http://example.com" or the other way around.

If however you want the user to like "example.com/#anchor" but when someone clicks on the liked link he will get to "example.com" then it's not possible.

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
  • I was trying the exact opposite ... sorry my english is bad .. how to explain .. I only have one html file so just one page but different sections like `example.com/#macro` and when someone enters that link a js script scrolls down to that section or opens a lightbox with a photo ... and when I try to share a link in this form it shares instead just `example.com` but I want it to share the entire `example.com/#photo`. – Iulian Onofrei May 13 '12 at 11:19
  • This is what i was talking: [example](http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fiulianonofrei.com%2F%23macro%2Fpanorama_3&t=Onofrei+Iulian+Photography&src=sp) if you look in the actual link you see the escaped link that I was trying to share `iulianonofrei.com/#macro/panorama_3` but in the actual page it shows only `iulianonofrei.com` – Iulian Onofrei May 13 '12 at 11:22
  • I just tried putting a url with hash (anchor) in the Like button guide page, then I liked it and indeed it liked that anchored url and not the generic one. Can you add the code you are using? – Nitzan Tomer May 13 '12 at 11:31
  • Oh, you are using the share, don't use that, it has been deprecated and it's no longer supported. Use the like button instead. – Nitzan Tomer May 13 '12 at 11:32
  • The codes fb give you need to be wrote in the html file directly? Because i'm trying to write them with jQuery and I can't get it working. – Iulian Onofrei May 13 '12 at 19:39
  • 1
    You can add it dynamically, just call [FB.XFBML.parse](http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/) afterwards – Nitzan Tomer May 13 '12 at 21:34
  • I done it but it still doesn't work as I expected. I have this code: `` and when I parse it, it shows it has no likes (my domain has 157 likes) as if it likes the actual link with the hashtag but on facebook it posts: `*username* has liked iulianonofrei.com` and not `*username* has liked iulianonofrei.com/#black_white/pissed_off` – Iulian Onofrei May 14 '12 at 23:13
  • They are probably putting it in a query string and then it gets mixed up with the original quesrystring. Try to url encode it, that is: `http://iulianonofrei.com/%23black_white/pissed_off` or even `http%3A%2F%2Fiulianonofrei.com%2F%23black_white%2Fpissed_off` – Nitzan Tomer May 14 '12 at 23:28
  • I tried escaping it and even putting it manually and it still shows 157 likes. Is this even possible? It gets very frustrating I can't get it working. – Iulian Onofrei May 15 '12 at 06:38
  • Ok, I think that your problem is the `og:url` meta tag. The facebook scrapper use that url to index things, and so you need to have the entire url (including the fragment part) in that meta tag. – Nitzan Tomer May 15 '12 at 07:00
  • No. the facebook scrapper does not deal with javascript, it gets the http response and uses that data. What you can do is check the user agent string of the request, if it's `facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)` then you know it's the facebook scrapper, and return the right meta tags. – Nitzan Tomer May 15 '12 at 07:26
  • any ideea how to do this or any link that would help me? because i don't have any ideea how to do this – Iulian Onofrei May 15 '12 at 15:00
  • what are you using on the server side? – Nitzan Tomer May 15 '12 at 15:10
  • Oh. Well, if your page is completely static then you can't do it. You'll need to have a different page per like, unless you don't mind the og data to be common with all likes. – Nitzan Tomer May 15 '12 at 15:21
  • what if i make a php file ... like `example.com/?c=macro&t=bird_nest`? – Iulian Onofrei May 15 '12 at 15:33
  • You'll need all pages to go through the php, people share what they see, if they copy the address and paste it in the facebook status update then that's what facebook will scrap. So, yeah, you can do that with php, but all pages need to be served like that. If you are going with that then check out: http://stackoverflow.com/questions/8626812/how-to-recognize-facebook-user-agent – Nitzan Tomer May 15 '12 at 15:40
1

I just thought about this (because I have the same problem). My idea is to share a php link with a variable, let's call it 'a' for anchor, which is the anchor without # so that facebook won't remore it. Thus you share the link: http://www.mywebpa.ge/?a=anchor1 Then you just have to recover the value of 'a' with php and add a little script which makes you go to the anchor. I hope it will help you. Regards

ek_
  • 41
  • 1