📜 ⬆️ ⬇️

Custom social buttons

Recently I participated in the development of one project - a photo of the competition. As planned, the rating of photo albums should be formed from the sum of all publications on social networks: Facebook, Vkontakte, Twitter. Those. The overall rating of the photo album is calculated:
Photo album rating = number “Share” on Facebook + number “Save” on Vkontakte + number “Retweet” on Twitter

On the layouts, the appearance of the buttons was somewhat different from the plug-ins provided by the api functions provided by social networks. In particular, the type of counters:
image
In addition to inconsistencies with the design, each plugin generates an excessive HTML code, and I would like to be concise.

After reading the api of each network in more detail, we are finally convinced that there are no advanced options for customizing the buttons, and this fact can be understood, everyone aspires to the uniqueness of their buttons. We decided to abandon the use of ready-made plug-ins and make your own buttons.

So:


Buttons


Each network has a script for processing requests to add pages using Share, Save, Tweet. At the same time, certain parameters are passed to the script. GET requests look like this:
')
Facebook:
_http: //www.facebook.com/sharer.php? u = <- url of the published page -> & t = <- title -> & src = sp
In contact with:
_http: //vkontakte.ru/share.php? url = <- url of the published page ->
Twitter
_http: //twitter.com/share? url = <- url of the published page -> & text = <- heading ->

To imitate the standard functionality, we make out the buttons as links with backgrounds:

image

I will not give CSS, I think this should not be difficult. For each link button, the href attribute must contain a url in accordance with the templates described above.

Before output, urls are brought to a safe view using urlencode (). We got the code like this:
  1. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  2. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  3. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  4. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  5. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  6. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  7. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  8. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  9. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  10. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  11. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  12. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  13. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  14. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  15. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
  16. < div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >
< div id = "social_block" > < div id = "vk_sharer" > < span > 53 < / span > < a id = "vk_btn" href = "_http://vkontakte.ru/share.php?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F" target = "_blank" title = " " >< / a > < / div > < div id = "fb_sharer" > < span > 116 < / span > < a id = "fb_btn" href = "_http://www.facebook.com/sharer.php?u=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&t=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0&src=sp" target = "_blank" title = " " >< / a > < / div > < div id = "tw_sharer" style = "" > < span > 31 < / span > < a id = "tw_btn" href = "_http://twitter.com/share?url=http%3A%2F%2Fsite.ru%2Fklasnaya-stranitsa%2F&text=%D0%9A%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D0%B0%D1%8F+%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0" target = "_blank" title = "Retweet" >Retweet< / a > < / div > < hr / > < div id = "total_count" > 200 < / div > < / div >

You can also take care of how the “post” will look like in a social network, for this we will place relevant meta tags in the < head > section of the page.

Facebook has Open Graph tags for this purpose:

< meta property = "og:title" content = "" / > <br/>
< meta property = "og:description" content = "" / > <br/>
< meta property = "og:image" content = "url " / >
< meta property = "og:title" content = "" / > <br/>
< meta property = "og:description" content = "" / > <br/>
< meta property = "og:image" content = "url " / >

Vkontakte will search for:

< meta name = "title" content = " " / > <br/>
< meta name = "description" content = " . ." / > <br/>
< link rel = "image_src" href = "_http://mysite.com/mypic.jpg" / >
< meta name = "title" content = " " / > <br/>
< meta name = "description" content = " . ." / > <br/>
< link rel = "image_src" href = "_http://mysite.com/mypic.jpg" / >

Next, we handle the click event of each button, when it occurs, we open a new browser window with the url specified in the href attribute, while the window is with the specified width and height, otherwise it will open as a new tab.

Code for the Facebook button (jQuery):

  1. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  2. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  3. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  4. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  5. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  6. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  7. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  8. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  9. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  10. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  11. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  12. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  13. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  14. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  15. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  16. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  17. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  18. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  19. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  20. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  21. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  22. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
  23. var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;
var click = false ; $ ( '#fb_btn' ) . click ( function ( ) { // if ( ! click ) { var social_box = $ ( this ) . parent ( 'div' ) ; // 1 var count = parseInt ( $ ( 'span' , social_box ) . text ( ) ) ; if ( ! isNaN ( count ) ) { count = count + 1 ; $ ( 'span' , social_box ) . text ( count ) ; } // 1 var total_cnt = parseInt ( $ ( '#total_count' ) . text ( ) ) ; if ( ! isNaN ( total_cnt ) ) { total_cnt = total_cnt + 1 ; $ ( '#total_count' ) . text ( total_cnt ) ; } click = true ; } // window. open ( $ ( this ) . attr ( "href" ) , 'displayWindow' , 'width=700,height=400,left=200,top=100,location=no, directories=no,status=no,toolbar=no,menubar=no' ) ; return false ; } ) ;

Similarly for the rest. With "sharing" as you can see everything is extremely simple.

Counters


The number of Shares for each page will be received from the REST services of social networks, after the page has been formed (ready event). Since jQuery was used throughout the project, it will also be useful here, in particular the $ .getJSON method, with the ability to perform cross-domain queries (although in jQuery 1.5, this feature was added to $ .ajax).

Code for Facebook:
  1. var pageuri = '<-- url -->' ; $. getJSON ( 'http://api.facebook.com/restserver.php?method=links.getStats&callback=?&urls=' + pageuri + '&format=json' , function ( data ) { // DOM $ ( '#fb_sharer span' ) . text ( data [ 0 ] . share_count ) ; } ) ;
  2. var pageuri = '<-- url -->' ; $. getJSON ( 'http://api.facebook.com/restserver.php?method=links.getStats&callback=?&urls=' + pageuri + '&format=json' , function ( data ) { // DOM $ ( '#fb_sharer span' ) . text ( data [ 0 ] . share_count ) ; } ) ;
  3. var pageuri = '<-- url -->' ; $. getJSON ( 'http://api.facebook.com/restserver.php?method=links.getStats&callback=?&urls=' + pageuri + '&format=json' , function ( data ) { // DOM $ ( '#fb_sharer span' ) . text ( data [ 0 ] . share_count ) ; } ) ;
  4. var pageuri = '<-- url -->' ; $. getJSON ( 'http://api.facebook.com/restserver.php?method=links.getStats&callback=?&urls=' + pageuri + '&format=json' , function ( data ) { // DOM $ ( '#fb_sharer span' ) . text ( data [ 0 ] . share_count ) ; } ) ;
  5. var pageuri = '<-- url -->' ; $. getJSON ( 'http://api.facebook.com/restserver.php?method=links.getStats&callback=?&urls=' + pageuri + '&format=json' , function ( data ) { // DOM $ ( '#fb_sharer span' ) . text ( data [ 0 ] . share_count ) ; } ) ;
var pageuri = '<-- url -->' ; $. getJSON ( 'http://api.facebook.com/restserver.php?method=links.getStats&callback=?&urls=' + pageuri + '&format=json' , function ( data ) { // DOM $ ( '#fb_sharer span' ) . text ( data [ 0 ] . share_count ) ; } ) ;

For Vkontakte, you need to declare two objects: VK and VK.Share, as well as the callback method VK.Share.count (index, count):
  1. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  2. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  3. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  4. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  5. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  6. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  7. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  8. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
  9. var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;
var pageuri = '<-- url -->' ; VK = { } ; VK. Share = { } ; // callback VK. Share . count = function ( index , count ) { // DOM $ ( '#vk_sharer span' ) . text ( count ) ; } ; $. getJSON ( 'http://vkontakte.ru/share.php?act=count&index=1&url=' + pageuri + '&format=json&callback=?' ) ;

For Twitter:
  1. var pageuri = '<-- url -->' ; $. getJSON ( 'http://urls.api.twitter.com/1/urls/count.json?url=' + pageuri + '&callback=?' , function ( data ) { // DOM $ ( '#tw_sharer span' ) . text ( data. count ) ; } ) ;
  2. var pageuri = '<-- url -->' ; $. getJSON ( 'http://urls.api.twitter.com/1/urls/count.json?url=' + pageuri + '&callback=?' , function ( data ) { // DOM $ ( '#tw_sharer span' ) . text ( data. count ) ; } ) ;
  3. var pageuri = '<-- url -->' ; $. getJSON ( 'http://urls.api.twitter.com/1/urls/count.json?url=' + pageuri + '&callback=?' , function ( data ) { // DOM $ ( '#tw_sharer span' ) . text ( data. count ) ; } ) ;
  4. var pageuri = '<-- url -->' ; $. getJSON ( 'http://urls.api.twitter.com/1/urls/count.json?url=' + pageuri + '&callback=?' , function ( data ) { // DOM $ ( '#tw_sharer span' ) . text ( data. count ) ; } ) ;
  5. var pageuri = '<-- url -->' ; $. getJSON ( 'http://urls.api.twitter.com/1/urls/count.json?url=' + pageuri + '&callback=?' , function ( data ) { // DOM $ ( '#tw_sharer span' ) . text ( data. count ) ; } ) ;
var pageuri = '<-- url -->' ; $. getJSON ( 'http://urls.api.twitter.com/1/urls/count.json?url=' + pageuri + '&callback=?' , function ( data ) { // DOM $ ( '#tw_sharer span' ) . text ( data. count ) ; } ) ;

After receiving the data, add them to the DOM and display the entire block with buttons for example:
$ ( '#social_block' ) . fadeIn ( 'fast); .
Eureka!

Rating update


In our case, the database of the competition for each photo album stores the values ​​of the counters for each network and the total rating. Therefore, after receiving data from social networks, they are compared with the data stored in the base of the site and, if at least one value is different, they are sent by ajax to update. Here everyone can have their own approach, so I will not focus.

I think the full code of the resulting jQuery plugin also makes no sense to post, who will need it, issue it to your taste. Of course, the same can be implemented with server-side scripts and using CURL for example, getting the same data, but it seemed more attractive to us to pass it on to the client side.

And one more thing: Facebook transferred the Share functionality to Like, but Share is still working and I hope it will continue. To get the number of likes, use the data [0] .like_count function in the callback.

Upd:
Archive with an example

Source: https://habr.com/ru/post/116584/


All Articles