Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Like Button with hash

when i try to add to my website a FB Like Button with url+hash (example.com/#TEST) and i try to click the like button - it shares the link without the hash in the news feed (example.com).

when i try to setup the button with "%23" instand of "#" (example.com/%23TEST) - it counts each hash separately in the count box.

is there any way to put a like button with hash - and still count the url without the hash?

Thanks!

like image 574
Erez Avatar asked Feb 21 '23 08:02

Erez


1 Answers

When you are creating Facebook like buttons, Facebook uses cURL (correct me people) to acces your URL that has metadata. So if cURL sees different metadata, per URL, you will get different LIKE buttons.

But this doesn't happen; as on the server side, Facebook sees the same URL for every dynamic # enabled link. Since the part of the link before # is same. JavaScript (or any Behavior that can create a hash in URL) is ignored, obviously, since its Behaviour is a client only thing.

The best possible way would be to create the Button dynamically using JavaScript and change the URL-to-like of each button to something friendly without hash.

abc.com/def#part1
abc.com/def#part2

// to
abc.com/def/part1
abc.com/def/part2

Only for the curl script to see it as a different URL.

And when the user hits that link - abc.com/def/part1 - you would be needing server side help as well to redirect to the view part1 from the route def. So you would, in your router code, load only upto the route def (imagine MVC) and then ask the controller to load the view part1, with JavaScript enabled to append the URL hash #part1.

like image 168
Om Shankar Avatar answered Mar 19 '23 08:03

Om Shankar