Click here to Skip to main content
12,701,539 members (34,925 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

13.7K views
33 downloads
6 bookmarked
Posted

Social Sharing Buttons using jQuery and XML

, 11 Jan 2017 CPOL
Rate this:
Please Sign up or sign in to vote.
Social sharing buttons using jQuery and XML

Update - 01/12/2017

Updated the code listing. Thanks to Chris Maunder for pointing out the code listing was broken. I also removed digg.com from the JavaScripts because it no longer functioning. Please note that this script was developed back in year 2011 and it's kind of old but still functioning. Please report any bugs.

Introduction

Yet another social sharing buttons script created by using jQuery and XML for your website. The script is very straight forward and self explanatory. The buttons container and buttons setting are stored in the XML file.

buttons in vertical

Figure 1

buttons in horizontal

Figure 2

How To Use It?

Listing 1

<!--solid, dotted, dashed, none -->
<divborderstyle>dashed
<!--Border width (int) -->
<divborderwidth>1
<!--Border color-->
<divbordercolor>#0000A0
<!--left, right, top, bottom -->
<divposition>left
<!--left or right (px) -->
<divmargin>50px
<<!--Div background color -->
<divbgcolor>#F9F9F9

You have the option to show or hide a particular social button.

Listing 2

<!--none, block -->
    <DisplayGooglePlusOne>block</DisplayGooglePlusOne>
    <DisplayFacebookLike>block</DisplayFacebookLike>
    <DisplayFacebookShare>none</DisplayFacebookShare>
    <DisplayTwitter>block</DisplayTwitter>
    <DisplayDigg>block</DisplayDigg>
    <DisplayStumbleUppon>block</DisplayStumbleUppon>
    <DisplayAddThis>block</DisplayAddThis>
  1. Download the SocialButton.xml and jquery.social-buttons.js file. This script requires the latest jQuery library, get it at http://jquery.com/.
  2. Open the SocialButton.xml and customize the necessary setting. You can customize the div container border style, width, color, position, and margin and background color. The DivMargin allows us to adjust the div container to the left and right.

  3. Open the jquery.social-buttons.js file and provide the location of the XML file on your server. Use absolute link if you are not sure of the relative path and make sure the script and XML file are in the same domain. For example:

    xml

    Figure 3

  4. Place the scripts before the body tag in the master page, template or web page that you want the social buttons to appear. For instance:

    scripts

    Figure 4

Frequent Questions and Answers

  1. Does your script work on different platforms?
    Yes, it should be cross-browser compatible.

  2. How come I don't see the social sharing button that I like?
    Currently, the script only provides the option to show or hide Google Plus One, Facebook like/Sharing, Twitter, Digg, StumbleUpon, and AddThis buttons. You can modify the script to fit your requirements.

  3. Is this script free?
    Yes. Use at your own risk.

  4. Why is there white space in between the buttons?
    Some buttons do not display the counter if the count is zero.

Conclusion

I hope someone will find this information useful and that it will make your programming job easier. If you find any bugs or disagree with the contents or want to help improve this article, please drop me a line and I'll work with you to correct it. I would suggest downloading the demo and exploring it in order to grasp the full concept of it because I might miss some important information in this article. Please send me an email if you want to help improve this article.

Watch This Script in Action

Demo

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bryian Tan
Software Developer (Senior)
United States United States
I have over three years of experience working with Microsoft technologies. I have earned my Microsoft Certified Technology Specialist (MCTS) certification. I'm a highly motivated self-starter with an aptitude for learning new skills quickly.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 12 Jan 2017
Article Copyright 2011 by Bryian Tan
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid